home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Tools & Apps (Moof!) / Testing & Debugging / Virtual User Libraries & Tools / VU Libraries / Controls.lib next >
Encoding:
Text File  |  1990-06-28  |  92.4 KB  |  2,503 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #                            Controls.lib
  3. #========================================================================
  4. # Description:    This is a library of general Virtual User tasks.  All of the
  5. #                tasks do their own error checking and status/error reporting.
  6. #                Most of them return a 1 if the action was successful and a 0
  7. #                if the action could not be performed. GetNewFileName() returns
  8. #                a new file name, MatchApp(), the current application's name,
  9. #                and GetXYRandom, a random X,Y coordinate pair. Tasks that do
  10. #                not return a value are marked with an *.
  11. #                The available tasks are listed below in order:
  12. #
  13. #            Initialization Tasks:
  14. #                InitControlGlobals()
  15. #                PrintGlobalValues()
  16. #
  17. #            Logging Tasks:
  18. #                LogStr(str, errorCheck,doTargetCheck)
  19. #                TargetInfo(theList)
  20. #                MatchApp(logMe,UpdateAppTitle)
  21. #
  22. #            Keyboard Tasks:
  23. #                TypeStr(str) *
  24. #                TypeList(List,Key, flag) *
  25. #                KeyEq(Alias,Otherkey) *
  26. #                SpecialKey(Key, keyName, n) *
  27. #
  28. #            Control Tasks:
  29. #                SelectMenuItem(menuName1, menuName2, menuName3)                    
  30. #                SelectButton(ButtonName)
  31. #                SelectRadioButton(RadioButtonName)
  32. #                SelectCheckBox(CheckBoxName)
  33. #                CheckYesNo(flag, DocName) *
  34. #
  35. #            Window Tasks:
  36. #                DialogCheck(FindStaticText, CommitButton)
  37. #                FindWindow(specifier)
  38. #                SelectWindow(specifier)
  39. #                DragWindow(h,v,specifier,absolutely)
  40. #                SizeWindow(X,Y,specifier,absolutely)
  41. #                ZoomWindow(specifier)
  42. #                ScrollWindow(foo,x,y)
  43. #                GetVHScrollBars()
  44. #                CloseWindow(howClose, overwrite, specifier, DocName)
  45. #
  46. #            Mouse Tasks:
  47. #                MoveRelativeToWindow(x, y, specifier, mouseDown, inset) *
  48. #                MoveMouse(x, y, absolutely , mouseDown) *
  49. #                DrawShapeFrame(specifier, theRect, inset)
  50. #
  51. #            File Related Tasks:
  52. #                NameOK(NameDoc, replaceFlag)
  53. #                GetNewFileName(name)    
  54. #                OpenDoc(namedoc, SelectOpen) *
  55. #
  56. #            Launch Tasks:
  57. #                Twitcher(appName, numIterations, waitTime)
  58. #                MiniLaunch(appTitle)
  59. #                LaunchTwitch(AppName, Folder, LaunchApp, SetDir)
  60. #
  61. #            String Tasks:
  62. #                IsSubString(str1, str2)
  63. #                FindPos(char, str, startPos)
  64. #                Substring(_String,_StartChar,_NumChar)
  65. #
  66. #            Misc. Tasks:
  67. #                Scrapbook(requestElement, ccpFlag, pasteFlag) *
  68. #                PageSetup()
  69. #                GetXYRandom(inset, specifier)
  70. #                IsNumber(whatAmI)
  71. #                PtInRect(thePoint,theRect)
  72. #                CenterOfScreenClick()
  73. #                Quit(OverWrite,DocName,HowQuit)
  74. #
  75. #     Copyright Apple Computer, Inc. 1985-1991
  76. #    All rights reserved
  77. #===============================================================================
  78. #     NJV/KTA    5/23/90        Created version 2.03
  79. #    NJV/KTA 7/20/90        Modified to 2.1. - For more info about tasks that
  80. #                        have changed since 2.03 the changes please refer to  
  81. #                        the task header. These changes should not affect your
  82. #                        current scripts. The fixes were for added functionality.
  83. #                        Globals were added for disabling individual features of 
  84. #                        LogStr.
  85. #                            LogStr()
  86. #                            TargetInfo()        (New)
  87. #                            MatchApp()
  88. #                            TypeList()             (New)
  89. #                            SpecialKey()
  90. #                            CheckYesNo()
  91. #                            SizeWindow()
  92. #                            ScrollWindow()
  93. #                            GetVHScrollBars()     (New)
  94. #                            CloseWindow()
  95. #                            MoveRelativeToWindow()
  96. #                            MoveMouse()
  97. #                            NameOK()
  98. #                            OpenDoc()
  99. #                            Scrapbook()
  100. #                            IsSubString()         (New)
  101. #                            FindPos()             (New)
  102. #    DM     9/18/90        Modified to 2.2. - Added DoSpecTest() and calls to include
  103. #                        Cdev.lib.vu and DA.lib.vu
  104. #    DM     9/24/90        Modified CloseWindw, MoveRelativeToWindow and GetXYRandom.
  105. #                        All calls are preserved except GetXYRandom. Added
  106. #                        general version of DrawShapeFrame.
  107. #    NJV    10/9/90            Bug fix in Scrapbook for 6.0 world
  108. #    NJV    11/27/90        Updated to version 2.4b3 by making the following changes:
  109. #                            + Docname wasn't explained in CloseWindow()
  110. #                            + Header for Quit() needed to be fixed
  111. #                            + Header for FindWindow() needed to be fixed
  112. #                            + Header for Opendoc() needed to be fixed
  113. #                            + Header for ScrapBook() needed to be fixed
  114. #                            + Header for NameOK() needed to be fixed
  115. #                            + Full names were taken out of headers
  116. #                            + bug fix and header update in SpecialKey()
  117. #                            + updated LaunchTwitch() and MiniLaunch() for new
  118. #                                version of MiniLauncher 1.3b
  119. #    NJV/KTA    12/18/90    Combined changes from 2 updated versions of Controls.lib
  120. #    KTA        12/20/90    Fixed bug in AppVerify scheme which included changes to
  121. #                        LaunchTwitch, LogStr, MatchApp
  122. #                        Also updated NameOK to handle dialog change in 7.0
  123. #    KTA     1/2/91        Added global BuildVers.
  124. #    KTA     1/8/91        Changed Scrapbook, Quit
  125. #    NJV/KTA 1/24/91        2.5b4 - Modified LaunchTwitch, Added check for warfare,
  126. #                        included Library include of Integrate.lib, added
  127. #                        code to support Integrate library
  128. #    NJV        1/28/91        Modified LaunchTwitch to disable integration
  129. #    KTA        2/5/91        Added DialogCheck for checking statictext in Dialogs
  130. #    KTA        2/18/91        InitControlGlobals() - added outputting of Global values.
  131. #                        Quit() - while(checkYesNo)
  132. #                        ScrapBook() - Global Integration := 0
  133. #                        LogStr() - Added LineItemTest
  134. #                        LogStr() - Took out Integration if DisableAllLogging
  135. #    NJV        3/28/91        2.5b5 - Updated Headers, changed LaunchTwitch,
  136. #                            added PrintGlobals()
  137. #    NJV        3/28/91        2.5b6 - took out integration module and the
  138. #                                following tasks not needed by developers:
  139. #                                Timer()
  140. #                                ETime()
  141. #                                DoSpecTestsInitial()
  142. #                                DoSpecTestsMiddle()
  143. #    NJV        4/16/91        Added StopOnBug global (implemented in LogStr)
  144. #    NJV        6/25/91        2.5b7 -    Added PtInRect routine, modified ZoomWindow
  145. #                                for better error checking, modified IsNumber
  146. #                                to use VU's new TypeOf function, modified
  147. #                                ScrollWindow to do scrollbar enable check
  148. #                                correctly.
  149. #########################################################################
  150.  
  151.  
  152.  
  153.  
  154. #########################################################################
  155. ####################            GLOBALS                #####################
  156. #########################################################################
  157. ### Global Library Definitions
  158. ###        If current value is 0 or 1, new value must be a 0 or 1
  159. ###        If current value is true or false, new value must be true or false
  160. ###        If current value is a string, new value must be a string
  161. ###
  162. #########################################################################
  163.  
  164.  
  165. #########################################################################
  166. #                            InitControlGlobals()
  167. #========================================================================
  168. # Author:        NJV
  169. # Description:    Initializes all global variables used by the Controls.lib
  170. #                library.  This task should be called immediately after
  171. #                the "Libraries 'Control.lib';" line in the script.  It
  172. #                is OK to modify the values of the variables.  This is how
  173. #                you customize your VU scripting environment and the way
  174. #                that your scripts will react using this library.
  175. # Parameters:    None
  176. # Returns:        Nothing
  177. # Examples:        InitControlGlobals();
  178. # Assumptions:    None 
  179. #
  180. ################################################################################
  181. ########### OK to modify the following GLOBAL Settings -  Be          ###########
  182. ########### careful that you understand what the Global is used for  ###########
  183. ################################################################################
  184. #========================================================================
  185. # History:
  186. #    NJV        3/28/91        Created
  187. #########################################################################
  188. Task InitControlGlobals() begin
  189.     println "Initializing Globals in Controls.lib 2.5b7";
  190.  
  191.     ## If AppVerify is set to 1, then the Application Verification scheme will
  192.     ## be activated.  This scheme is documented in the "SIAC's Reference"
  193.     ## document (which accompanies this library on the Developer CD).
  194.     ## 
  195.     
  196.     global AppVerify := 0;            # 1 to enable Application Verification Scheme
  197.                                     # 0 to disable Application Verification Scheme
  198.  
  199.     global StopOnBug := 0;            # 1 to stop when LogStr encounters a warning (error)
  200.                                     #   message
  201.                                     
  202.     ### To set Target descriptor output ###
  203.     global TargetInfoDescriptor := 'Target';    # Descriptor to use 'Target' is the one only defined currently
  204.     global TargetCheck := 0;    # 1 for target title; 2 for target application title
  205.         
  206.     global BugsOn := 0;                        # set to 1 for known bugs to be tested
  207.     
  208.     ############################################################################
  209.     ####### DO NOT modify any of the following GLOBAL Settings -      ############
  210.     ####### DisableAllLogging may be reset during script execution  ############
  211.     ############################################################################
  212.         Sys := match[system v:?Sysname];    # To match system build
  213.     global BuildVers := "{Sysname}";
  214.             if ((Sysname ~= /≈7.0≈/) or (Sysname ~= /≈Warfare≈/) or (Sysname ~= /≈Regatta≈/))
  215.                 Global isSys7 := true;
  216.             else
  217.                 Global isSys7 := False;
  218.             
  219.     global LogStrCount := 0;                # Initializes our LogStr Counter
  220.     global LastSavedFile;                    # Contains the name of the last file saved in NameOK();
  221.     global AppTitle := "";                    # Current application title for AppVerify()
  222.     global PrevAppTitle := "";                # Previous application title for twitching
  223.     global DisableAllLogging := 0;            # 1 if no logging (run time modify only)
  224.     Global FileShareFlag;                    # Holds the current status of  Filesharing if 
  225.     PrintGlobals();                            # print the global values to output
  226.     println;
  227. end;                                        # SharingSetup() was called.
  228.  
  229.  
  230. #########################################################################
  231. #                            PrintGlobals()
  232. #========================================================================
  233. # Author:        NJV
  234. # Description:    Prints the values of all Control Globals
  235. # Parameters:    None
  236. # Returns:        Nothing
  237. # Examples:        PrintGlobals();
  238. # Assumptions:    None 
  239. #========================================================================
  240. # History:
  241. #    NJV        3/28/91        Created
  242. #########################################################################
  243. task PrintGlobals() begin
  244. global BuildVers;
  245.  
  246.     if (global DisableAllLogging)
  247.         println "All logging is disabled";
  248.     else
  249.         println "All logging is enabled";
  250.  
  251.     if (global AppVerify)
  252.         println "The 'Application Verification' scheme is turned - ON";
  253.     else
  254.         println "The 'Application Verification' scheme is turned - OFF";
  255.  
  256.     if (global TargetCheck) begin
  257.         if (TargetCheck= 1)
  258.             TCItem := "the target's 'Title'";
  259.         else if (TargetCheck= 2)
  260.             TCItem := "the title of the target's current 'Application'";
  261.         println "The global 'TargetCheck' is set to output - {TCItem}";
  262.     end;
  263.         
  264.     if (global BugsOn) 
  265.         println "The global 'BugsOn' has been activated - Cross your fingers!!!";
  266.  
  267.     if (global Spectest)                         # DoSpecTestsInitial and DoSpecTestsMiddle
  268.         println "The global 'Spectest' is - ON. Does this effect you???";
  269.  
  270.     Println "The current system is - '{BuildVers}'";
  271. end;
  272.  
  273. #########################################################################
  274. #                    LogStr(str, errorCheck,doTargetCheck)
  275. #========================================================================
  276. # Author:        KTA
  277. # Description:    Match the target and print it with whatever is passed
  278. #                to it in the 'str' parameter.  If the errorCheck
  279. #                parameter is 1, then the current application will be
  280. #                checked to make sure it is the same as the expected
  281. #                application.  If it is not, LogStr will assume that the
  282. #                application has crashed and will abort the script.
  283. #                If the errorCheck parameter is not passed, then the
  284. #                default behavior will not perform this check.
  285. # Parameters:    str - string to be printed
  286. #                errorCheck -    0 to bypass error checking
  287. #                                1 to enable error checking
  288. #                targetCheck - 0 to bypass calling of TargetInfo
  289. #                            - theList, which is
  290. #                         theList[1] - what to match for - default 'Target'
  291. #                        theList[2] - Specifier of what info to return
  292. #                        If theList[1] = 'Target'then    
  293. #                            if theList[2] = 
  294. #                                 1 - Return Title for target
  295. #                                 2 - Returns Application running on Target
  296. # Returns:        Nothing
  297. # Examples:        LogStr("It worked");
  298. #                LogStr("It worked",1,1);
  299. #                LogStr("It worked",1,{1,2});
  300. # Assumptions:        None 
  301. #========================================================================
  302. # History:
  303. #    KTA        4/1/90        Created
  304. #    KTA        4/29/90        This routine now checks to make sure the global
  305. #                        AppTitle equals the current application running -
  306. #                        if not, it assumes that the target crashed and
  307. #                        aborts the script.
  308. #    NJV        5/15/90        Added errorCheck parameter for disabling error
  309. #                        checking.
  310. #    NJV        7/9/90        Added targetCheck for disabling target matching
  311. #    NJV/KTA    7/13/90        Added TargetInfo mechanism 
  312. #    KTA        7/19/90        Added key equivelant 'Q'; to quit the current app if
  313. #                        it doesn't match
  314. #    NJV        7/24/90        Moved LogStrCount into not DisableAllLogging block
  315. #    KTA        8/2/90         Added - if not( theAppTitle ~= /≈{global AppTitle}≈/)
  316. #    NJV/KTA    12/18/90     Added - Retry for AppVerify 
  317. #    KTA        12/20/90     Reworked errorCheck to work with  new MatchApp
  318. #    KTA        2/18/91     Added LineItemTest
  319. #    KTA        2/19/91     Took out integration if DisableAllLogging is on.
  320. #    NJV        3/31/91        Took out integration for Developer CD - not needed
  321. #    NJV        3/31/91        Took out LineItemTest
  322. #    NJV        4/16/91        Added StopOnBug block to stop on warning message
  323. #########################################################################
  324. task LogStr(str, errorCheck := global AppVerify,doTargetCheck := global TargetCheck) begin
  325.     global AppTitle;
  326.     theStr := '';
  327.  
  328.     if (global StopOnBug) begin
  329.         if (isSubString("!@#$%",str))    # it's a warning message, exit script
  330.             exit;
  331.     end;
  332.     
  333.     if (doTargetCheck)
  334.         theStr := TargetInfo(doTargetCheck);
  335.     if (not global DisableAllLogging) begin
  336.         global LogStrCount := LogStrCount + 1;
  337.         println LogStrCount," - ",str," {theStr}";
  338.     end;
  339.     if (errorCheck) begin
  340.         theAppTitle := MatchApp(0,0);
  341.         retry := 2;
  342.         while not(theAppTitle ~= /≈"{AppTitle}"≈/) begin    # assume target crashed if app name not match
  343.             theAppTitle := MatchApp(0,0);
  344.             if retry begin
  345.                 retry := retry - 1;
  346.                 LaunchTwitch(AppTitle,, 0);
  347.             end;
  348.             else begin
  349.                 println "*** Current application: '{theAppTitle}'   *** Expected application: '{AppTitle}'";
  350.                 println "*** Target application is off track - aborting script and typing key Equivalent 'Q'";
  351.                 PressKey K:{CommandKey};
  352.                 Type k: {'q'};
  353.                 ReleaseKey K:{CommandKey};
  354.                 exit;
  355.             end;
  356.         end;
  357.     end;
  358.     Return(1);
  359. end; # LogStr()
  360.  
  361.  
  362. #########################################################################
  363. #                            TargetInfo(theList)
  364. #========================================================================
  365. # Author:        NJV/KTA
  366. # Description:    Match whatever is specified in global TargetInfoDescriptor
  367. #                and will return the appropriate string.
  368. # Parameters:    theList[1] - what to match for - default 'Target'
  369. #                theList[2] - Specifier of what info to return
  370. #                    If theList[1] = 'Target'then    
  371. #                        if theList[2] = 
  372. #                         1 - Return Title for target
  373. #                         2 - Returns Application running on Target
  374. # Returns:        Str
  375. # Examples:        global TargetInfoDescriptor := 1;    
  376. #                global TargetInfoDescriptor :={1,2};
  377. #========================================================================
  378. # History:
  379. #    NJV/KTA    7/13/90    Created
  380. #########################################################################
  381. task TargetInfo(theList) begin
  382.     theDesc := global TargetInfoDescriptor;
  383.     if (not isList)     begin    # a single number
  384.         list2 := {theList};
  385.     end;    
  386.     else begin                    # a list
  387.         list2 := theList;
  388.         if (not card(list2))     # a single number
  389.             list2 := {theList};
  390.     end;
  391.  
  392.     # load theDescInfo with the info on the specified target
  393.     if (theDesc = 'Target') begin
  394.         theDescInfo := match [target]!;
  395.         TargetTitle := theDescInfo.t;
  396.         App := theDescInfo.a;
  397.         theAppTitle :=App[1].t;
  398.         
  399.         if not theDescInfo
  400.             return('');
  401.         str := "(Target -";
  402.     end;
  403.             
  404.     for each item in list2 begin
  405.         if ((theDesc = 'Target') and (item = 1))    # title
  406.             str := "{str} Title:∂'{TargetTitle}∂'";
  407.         else if ((theDesc = 'Target') and (item = 2))    # App
  408.             str := "{str} Application:∂'{theAppTitle}∂'";
  409. #        else if ((theDesc = 'Target') and (item = 3)) begin    # CPU
  410. #            theCPU := theDescInfo.n;
  411. #            str := "{str} CPU: " + {theCPU};
  412. #        end;
  413.     end;
  414.         
  415.     str := "{str})";
  416.     return(str);
  417. end;
  418.  
  419.  
  420. #########################################################################
  421. #                     MatchApp(logMe,UpdateAppTitle)
  422. #========================================================================
  423. # Author:            KTA
  424. # Description:        This routine will match the current Application and,
  425. #                    if the logMe parameter is 1, will log the current
  426. #                    application name by passing it to LogStr().  If a
  427. #                    parameter is not passed, the default behavior will
  428. #                    log the application's title.  This routine will also
  429. #                    set the global AppTitle to the application's title.
  430. #                    Output appears in the following format:
  431. #                            [application t:"Finder"]
  432. # Parameters:        logMe - 1 to print the current application's title
  433. #                            0 not to print the application's title
  434. #                    UpdateAppTitle     - 1 to update the global AppTitle
  435. #                                    - 0 not to update global AppTitle
  436. # Return Value:        string holding current application's title
  437. # Examples:            MatchApp();
  438. # Assumptions:        there is an active application
  439. #========================================================================
  440. # History:
  441. #    KTA        3/16/90        Created 
  442. #    KTA        4/28/90        Makes a call to global Apptitle to Verify App
  443. #    KTA        5/7/90        Added parameter to allow bypassing of LogStr() call.
  444. #    NJV        5/13/90        Now returns title of application
  445. #    KTA        7/13/90        Took out initial 5 second wait
  446. #    KTA        12/20/90    Added UpdateAppTitle
  447. #########################################################################
  448. task MatchApp(logMe := 1, UpdateAppTitle :=1) begin
  449.     AppName := match[application];
  450.     if UpdateAppTitle
  451.         global AppTitle := AppName.t;            #to Verify App
  452.     else begin
  453.         TheAppTitle := AppName.t;
  454.         Return(TheAppTitle);
  455.     end;
  456.     str := "The current application is '{AppTitle}'";
  457.     temp := global DisableAllLogging;
  458.     if logMe begin 
  459.         DisableAllLogging := 0;
  460.         LogStr(str);
  461.     end;
  462.     DisableAllLogging := temp;
  463.     return(AppTitle);
  464. end; # MatchApp()
  465.  
  466. #########################################################################
  467. #                                TypeStr(str)
  468. #========================================================================
  469. # Author:        KTA
  470. # Description:    This routine will type whatever is passed in as the String.
  471. # Parameters:    str - string to be typed
  472. # Returns:        Nothing
  473. #========================================================================
  474. # History:
  475. #    KTA        1/20/90        Created
  476. #    KTA        1/9/91        Added default parameter ''
  477. #########################################################################
  478. task TypeStr(str :='') begin
  479.     type k:{str};
  480.     LogStr("Typed '{str}'");
  481. end; # TypeStr()
  482.  
  483.  
  484. #########################################################################
  485. #                        TypeList(theList,Key, flag)
  486. #========================================================================
  487. # Author:            KTA
  488. # Description:        This routine will type each item in the {list} and the 
  489. #                    selected special key after each item. If flag = 0 the 
  490. #                    special key will be suppressed after the last item.
  491. # Parameters:        theList -    list holding strings to type
  492. #                    Key    -        int representing key to type after the item
  493. #                                has been typed. 
  494. #                        key := 1 (ReturnKey)
  495. #                        Key := 2 (TabKey)
  496. #                        Key := 3 (EnterKey)
  497. #                    flag -     1 to type special key after last item in list
  498. #                            0 to disable typing of last special key
  499. # Return Value:        None
  500. # Examples:            TypeList({'A','list', 'of items'},2); To type each item 
  501. #                    and then the tabKey
  502. # Assumptions:        None 
  503. #========================================================================
  504. # History:
  505. # KTA    7/1/90    Created
  506. # DMM     7/2     Flag to type special key after last item
  507. # KTA    8/20/90    Added check to see if key is defined before adding 'and' to {item}
  508. ################################################################################    
  509. task TypeList(theList,Key := 0, flag := 0) begin
  510.     x := 0;
  511.     y := card(theList);
  512.     if (flag)                 #Type final Special Key after the last item
  513.         y := y +1;
  514.      for each item in theList begin
  515.         x := x + 1;
  516.         KeyName := '';
  517.         type k:{item};
  518.         if (x < y) begin  #don't suppress special key after last item
  519.             if ((key = 1) or (key = 'ReturnKey')) begin
  520.                 type k:{ReturnKey};
  521.                 keyName := 'the Return Key';
  522.             end;
  523.             else if ((key = 2) or (key = 'TabKey')) begin
  524.                 type k:{TabKey};
  525.                 keyName := 'the Tab Key';
  526.             end;
  527.             else if ((key = 3) or (key = 'EnterKey')) begin
  528.                 type k:{EnterKey};
  529.                 keyName := 'the Enter Key';
  530.             end;
  531.         end;    
  532.         if ((x < y) and (Key <> 0) and ((item <> "") or (IsNumber(item))))
  533.             item := "∂'{item}∂' and ";
  534.         LogStr("Typed {item}{KeyName}");
  535.     end;
  536. end; # TypeList
  537.  
  538.  
  539. #########################################################################
  540. #                            KeyEq(Alias,Otherkey)
  541. #========================================================================
  542. # Author:        KTA
  543. # Description:    This routine will select the Keyboard Equiv <alias>
  544. # Parameters:    alias -        string holding character to be typed with
  545. #                            command key down.
  546. #                OtherKey -    int representing special keys to hold down in
  547. #                            conjunction with the command key
  548. #                    0 - no other keys are to be held down
  549. #                    1 - Shift key
  550. #                    2 - Option key
  551. # Returns:        None
  552. # Examples:        KeyEq("q");
  553. #========================================================================
  554. # History:
  555. #    KTA        4/1/90        Created
  556. #    KTA        7/31/90        Added MatchApp for 'w' and 'q'
  557. #    KTA/PF    8/14/90        Added Shift key Functionality
  558. #    KTA        8/16/90        Added Option key Functionality
  559. #########################################################################
  560. task KeyEq(Alias,Otherkey := 0) begin
  561.     if (Otherkey =1) begin
  562.         pressKey k:{ commandKey,ShiftKey };
  563.         type k : { alias };
  564.         releaseKey k:{ commandKey,ShiftKey };
  565.         LogStr("Pressed the ∂('{alias}'∂) key and the Command-Shift keys");
  566.     end;
  567.     else if (Otherkey = 2) begin
  568.         pressKey k:{ commandKey,Optionkey };
  569.         type k : { alias };
  570.         releaseKey k:{ commandKey,Optionkey };
  571.         LogStr("Pressed the ∂('{alias}'∂) key and the Command-Option keys");
  572.     end;
  573.     else begin
  574.         pressKey k:{ commandKey };
  575.         type k : { alias };
  576.         releaseKey k:{ commandKey };
  577.         if (global AppVerify) begin
  578.             if ((alias = 'w') or (alias = 'q')) begin
  579.                 wait(2);
  580.                 matchApp(0);
  581.             end;
  582.         end;
  583.         LogStr("Pressed the ∂('{alias}'∂) key and the Command key");
  584.     end;
  585. end; # KeyEq()
  586.  
  587.  
  588. #########################################################################
  589. #                        SpecialKey(Key,keyName,n)
  590. #========================================================================
  591. # Author:        KTA
  592. # Description:    This routine will type whatever SpecialKey is entered
  593. #                However it will only log the name of the special character 
  594. #                if the special key name is also passed in as a String in
  595. #                the keyName parameter.
  596. # Parameters:    Key - the VU key-word for the special key to be typed
  597. #                keyName - the string name of the special key
  598. #                n - number of times to type the special key (default = 1)
  599. # Returns:        Nothing
  600. # Examples:        SpecialKey(TabKey,"TabKey");
  601. #========================================================================
  602. # History:
  603. #    KTA        4/25/90        Created
  604. #    KTA     7/5/90        Added n parameter for number of times to be completed.
  605. #    NJV        11/27/90    bug fix - if no keyName and n > 1, then str was typed
  606. #                        every time instead of once.  Also updated header.
  607. #########################################################################
  608. task SpecialKey(Key,keyName:="",n :=1) begin
  609.     for x := 1 to n do
  610.         type k:{ Key };
  611.     if (n <> 1) begin
  612.         if (keyName ="")
  613.             LogStr("Typed some special key - ({n}) times");
  614.         else
  615.             LogStr ("Typed {keyName} - ({n}) times");
  616.     end;
  617.     else begin
  618.         if (keyName ="")
  619.             LogStr("Typed some special key");
  620.         else
  621.             LogStr ("Typed {keyName}");
  622.     end;
  623. end; # SpecialKey()
  624.  
  625.  
  626. ########################################################################
  627. #                 SelectMenuItem(menuName1, menuName2, menuName3)                    
  628. #=======================================================================
  629. # Author:           SL
  630. # Description:        Selects the menu item by its name.
  631. # Parameters:        menuName1 := Menu item to be selected.
  632. #                    menuName2 := Menu name if non-hier menu and
  633. #                                 Level 2 menu item if hier menu.
  634. #                    menuName3 := "" if non-hier menu.
  635. #                                 Menu name if hier menu.
  636. # Returns:            menuTitle - MenuItem name that selection was successful
  637. #                    0 - Couldn't select menu item
  638. # Notes:                Do not have to pass 'menuName2' or 'menuName3'
  639. #                    as a parameter.  In that case, default value, "",
  640. #                    will be used.
  641. #=======================================================================
  642. # History:
  643. #    SL        4/4/90        Created
  644. #    KTA        5/16/90        MatchApp Verification
  645. #    KTA        8/7/90        Return menuTitle
  646. ########################################################################
  647. task SelectMenuItem(menuName1, menuName2 := "", menuName3 := "") 
  648. begin
  649.     if (menuName3 = "")                    # Match non-hier menus            
  650.         begin
  651.             ourMenuItem := match [menuItem t: menuName1 m:[menu t: menuName2]];
  652.             if (ourMenuItem = [])
  653.                 ourMenuItem := match [menuItem t: menuName1];
  654.         end;
  655.     else
  656.         begin                            # Match hier menus                
  657.             ourMenuItem :=match [menuItem t:menuName1 
  658.                                             m:[menuitem t:menuName2 
  659.                                           m:[menu t:menuName3]]];
  660.             if (ourMenuItem = [])
  661.                 ourMenuItem :=match [menuItem t:menuName1 m:[menuItem t:menuName2]];
  662.             if (ourMenuItem = [])
  663.                 ourMenuItem :=match [menuItem t:menuName1];
  664.         end; # else
  665.  
  666.     if (ourMenuItem = []) 
  667.         begin
  668.             LogStr("!@#$% Could not find menu item {menuName1} to select");
  669.             return(0);
  670.         end;
  671.     else 
  672.         if (ourMenuItem.e = false) begin
  673.             LogStr("!@#$% Menu item {menuName1} is not enabled to select.");
  674.             return(0);
  675.         end;
  676.     else
  677.         select ourMenuItem!;
  678.         menuTitle := ourMenuItem.t;
  679.         if (global AppVerify) begin
  680.             if ((menuTitle = 'Close') or (menuTitle = 'Quit')) begin
  681.                 wait(2);
  682.                 matchApp(0);
  683.             end;
  684.         end;
  685.         LogStr("Selected the '{menuTitle}' menu item");
  686.     return(menuTitle);
  687. end; # SelectMenuItem()
  688.  
  689.  
  690. #########################################################################
  691. #                        SelectButton(ButtonName)
  692. #========================================================================
  693. # Author:        KTA
  694. # Description:    This routine will select the button named (ButtonName)
  695. # Parameters:    ButtonName - string holding name of button to select
  696. # Returns:        0 - Couldn't select button
  697. #                1 - Selected button OK
  698. #========================================================================
  699. # History:
  700. #    KTA        3/20/90        Created
  701. #    NJV        5/13/90        Added checking to assure button is enabled
  702. #########################################################################
  703. task SelectButton(ButtonName) begin
  704.     rix := match [button t:ButtonName e:1]!;
  705.     if rix begin
  706.         Select [button t:ButtonName];
  707.         str := "Selected Button titled '{ButtonName}'";
  708.         LogStr(str);
  709.         return(1);
  710.     end;
  711.     else begin
  712.         if (match [button t:ButtonName]!)
  713.             str := "!@#$% Couldn't select button named '{ButtonName}' because it's not enabled";
  714.         else
  715.             str:= "!@#$% There was no button named '{ButtonName}'";
  716.         LogStr(str);
  717.         return(0);
  718.     end;
  719. end; # SelectButton()
  720.  
  721. #########################################################################
  722. #                    SelectRadioButton(RadioButtonName)
  723. #========================================================================
  724. # Author:        KTA
  725. # Description:    This routine will select RadioButton named (RadioButtonName)
  726. # Parameters:    RadioButtonName - string name of radio button to select
  727. # Returns:        0 - Couldn't select radio button
  728. #                1 - Selected button OK
  729. #========================================================================
  730. # History:
  731. #    KTA        3/20/90        Created    
  732. #    NJV        5/13/90        Added checking to assure radio button is enabled
  733. #########################################################################
  734. task SelectRadioButton(RadioButtonName) begin
  735.     rix := match [RadioButton t:RadioButtonName e:1]!;
  736.     if rix begin
  737.         Select [RadioButton t:RadioButtonName];
  738.         str := "Selected radio button titled '{RadioButtonName}'";
  739.         LogStr(str);
  740.         return(1);
  741.     end;
  742.     else begin
  743.         if (match [RadioButton t:RadioButtonName]!)
  744.             str := "!@#$% Couldn't select radio button named '{RadioButtonName}' because it's not enabled";
  745.         else
  746.             str:= "!@#$% There was no radio button named '{RadioButtonName}'";
  747.         LogStr(str);
  748.         return(0);
  749.     end;
  750. end; # SelectRadioButton()
  751.  
  752. #########################################################################
  753. #                        SelectCheckBox(CheckBoxName)
  754. #========================================================================
  755. # Author:        KTA
  756. # Description:    This routine will select CheckBox named (CheckBoxName)
  757. # Paramters:    CheckBoxName - string name of check box to select
  758. # Returns:        0 - Couldn't select check box
  759. #                1 - Selected check box OK
  760. #========================================================================
  761. # History:
  762. #    KTA        3/20/90        Created    
  763. #    NJV        5/13/90        Added checking to assure check box is enabled
  764. #########################################################################
  765. task SelectCheckBox(CheckBoxName) begin
  766.     rix := match [CheckBox t:CheckBoxName]!;
  767.     if rix begin
  768.         Select [CheckBox t:CheckBoxName];
  769.         str := "Selected check box titled '{CheckBoxName}'";
  770.         LogStr(str);
  771.         return(1);
  772.     end;
  773.     else begin
  774.         if (match [CheckBox t:CheckBoxName]!)
  775.             str := "!@#$% Couldn't select check box named '{CheckBoxName}' because it's not enabled";
  776.         else
  777.             str:= "!@#$% There was no check box named '{CheckBoxName}'";
  778.         LogStr(str);
  779.         return(0);
  780.     end;
  781. end; # SelectCheckBox()
  782.  
  783.  
  784. #########################################################################
  785. #                CheckYesNo(flag, DocName)
  786. #========================================================================
  787. # Author:        SL
  788. # Description:    Checks for dialog boxes with "Yes" (or "OK") and "No"
  789. #                buttons. If they are found, clicks one of the buttons
  790. #                depending on the 'flag' parameter.
  791. # Parameters:    flag -    TRUE - Selects "Yes"  or "OK" button.
  792. #                        FALSE - Selects "No" button.
  793. #                DocName - Name that docment will be saved with.
  794. # Returns:        Nothing
  795. #========================================================================
  796. # History:
  797. # SL        4/3/90        Created
  798. # KTA/NV    7/17/90        Added DocName parameter for Nameok
  799. #########################################################################
  800. task CheckYesNo(flag := true, DocName := "")
  801. begin
  802.     wait(1);
  803.     yesBtn := match[button t:"Yes" w:[window o:1]]!;
  804.     noBtn  := match[button t:"No"  w:[window o:1]]!;
  805.     okBtn  := match[button t:"Ok"  w:[window o:1]]!;
  806.     if (yesBtn or okbtn ) and flag begin
  807.         if (yesBtn)
  808.             SelectButton("Yes");
  809.         else if (okbtn)
  810.             SelectButton("OK");
  811.         wait(1);
  812.         if (match[button t:"Save"]!) or (match[button t:"OK"]!)        # If SF dialog comes up     #
  813.             NameOk(DocName,true);
  814.         else
  815.             type k:{ReturnKey};
  816.     end; # if
  817.     else
  818.         if noBtn and (not flag)
  819.             SelectButton("No");
  820.     wait(1);
  821. end; # CheckYesNo()
  822.  
  823.  
  824. #########################################################################
  825. #                            FindWindow(specifier)
  826. #========================================================================
  827. # Author:        DM
  828. # Description:    FindWindow will return the descriptor of the window
  829. #                specified by the parameter specifier.
  830. # Parameters:    specifier - if string, then it holds title of window
  831. #                            if integer, then it holds ordinality of window
  832. # Returns:        0 - Couldn't find the window
  833. #                1 - found the window OK
  834. #========================================================================
  835. # History:
  836. #    DM        9/27/90        Created
  837. #    NJV        11/27/90    Added documentation
  838. #########################################################################
  839. task FindWindow(specifier := "None") begin
  840.     if(specifier = "None") begin
  841.         LogStr("Null specifier passed as a parameter to FindWindow");
  842.         return 0;
  843.     end;
  844.     if (not (IsNumber(specifier))) begin
  845.         theDesc := match [window t:specifier]!;
  846.         if (not theDesc) begin
  847.             LogStr("!@#$% Couldn't match a window of title {specifier}");
  848.             return(0);
  849.         end;
  850.     end;
  851.     else if(specifier > 0) begin
  852.         theDesc := match[window o:specifier]!;
  853.         if (not theDesc) begin
  854.             LogStr("!@#$% Couldn't match a window of ordinality {specifier} with a grow box");
  855.             return(0);
  856.         end;
  857.     end;
  858.     else if(specifier = 0) begin
  859.         theDesc := match[window c:true g:true]!;
  860.         if (not theDesc) begin
  861.             LogStr("!@#$% Couldn't match a window with a close and grow box");
  862.             return(0);
  863.         end;
  864.     end;
  865.     else if (specifier < 0) begin
  866.         scrList := collect[screen]!;
  867.         theDesc := scrList[-specifier];
  868.     end;
  869.     return theDesc;
  870. end;
  871.  
  872. ########################################################################
  873. #                        DialogCheck(FindStaticText,CommitButton)
  874. #=======================================================================
  875. # Author:        KTA
  876. # Description:    This routine will to match a dialog of ordinality 1,
  877. #                with StaticText - {FindStaticText}, if found it will select the 
  878. #                Button - {CommitButton}.
  879. # Parameters:    FindStaticText - StaticText string that you want to match
  880. #                CommitButton   - Button to select if the static text is found.
  881. # Returns:        1 - Found FindStaticText and selected CommitButton
  882. #                0 - Couldn't find FindStaticText
  883. #=======================================================================
  884. # History:
  885. #     KTA        2/5/91        Created
  886. #     KTA        2/19/91        
  887. ########################################################################
  888. task DialogCheck(FindStaticText :='', CommitButton :="OK") 
  889. begin
  890.     DialogWin :=  collect[staticText w:[window o:1 c:false s:dialog]]!; 
  891.     if (DialogWin) 
  892.     begin
  893.         for each StaticItem in DialogWin 
  894.         begin
  895.         theStaticText :=  StaticItem.t;
  896.             if not( theStaticText = '') 
  897.             begin
  898.                 if(IsSubString(FindStaticText, theStaticText)) 
  899.                 begin
  900.                     println;
  901.                     LogStr("Found Dialog: '{theStaticText}'");
  902.                     SelectButton(CommitButton);
  903.                     println;
  904.                     return(theStaticText);
  905.                 end;
  906.             end;
  907.         end;
  908.     end;
  909.     else 
  910.         return(0);
  911. end;  #DialogCheck()
  912.  
  913. ########################################################################
  914. #                        SelectWindow(specifier)
  915. #=======================================================================
  916. # Author:        NJV
  917. # Description:    This routine will select a window specified by
  918. #                ordinality or title.
  919. # Parameters:    specifier -    holds the title or ordinality of window to
  920. #                            select.
  921. # Returns:        1 - Selected window OK
  922. #                0 - Couldn't find window to select
  923. #=======================================================================
  924. # History:
  925. #     NJV        4/7/90        Created
  926. #    NJV        5/13/90        Condensed two parameters to one
  927. #    DM        9/27/90        Optimized and added FindWindow
  928. #    ECH        11/7/90        Changed default parameter to 0 to let FindWindow
  929. #                        do its work.
  930. ########################################################################
  931. task SelectWindow(specifier := 0) begin
  932.     theWind := FindWindow(specifier);
  933.     if theWind begin
  934.         windOrd := theWind.o;
  935.         title := theWind.t;
  936.         select [window o:windOrd t:title]!;
  937.         LogStr("Selected window of ordinality {windOrd} (titled '{title}')");
  938.         return(1);
  939.     end;
  940.     else begin
  941.         if(IsNumber(specifier))
  942.             Str1 := "!@#$% There was no window of ordinality {specifier} to select";
  943.         else
  944.             Str1 := "!@#$% There was no window titled '{specifier}'";
  945.         LogStr(Str1);
  946.         return(0);
  947.     end;
  948. end;  # SelectWindow()
  949.  
  950.  
  951. #########################################################################
  952. #                DragWindow(h,v,specifier,absolutely)
  953. #========================================================================
  954. # Author:        KTA
  955. # Description:    This routine will drag the specified window
  956. #                'h' pixels horizontally (-h drags left) and 'v' pixels
  957. #                vertically (-v drags up)
  958. # Parameters:    h    - Horizontal pixel offset to drag the window
  959. #                v    - Vertical pixel offset to drag the window
  960. #                specifier - holds title or ordinality of window to drag
  961. #                absolutely -    1 if absolute drag
  962. #                            0 if relative drag
  963. # Returns:        1 - Dragged window OK
  964. #                0 - Couldn't find window to drag
  965. #========================================================================
  966. # History:
  967. #    KA        4/6/90        Created
  968. #     NJV        4/7/90        Allows for dragging by title or ordinality
  969. #     NJV        4/26/90        Changed to allow for absolutely or relative drag
  970. #    NJV        5/13/90        Condensed parameter list
  971. #    DM        9/27/90        Optimized and added FindWindow
  972. #                        Changed specifier default to 0 so it will match the 
  973. #                        first document window.
  974. #########################################################################
  975. task DragWindow(h := "random", v := "random", specifier:=0,absolutely:=1) begin
  976.     if (h = "random") begin    # user wants random coordinates
  977.         xyRandom := getXYRandom(,-1);
  978.         h := xyRandom[1];
  979.         v := xyRandom[2];
  980.     end;
  981.  
  982.     theWind := FindWindow(specifier);
  983.     if theWind begin
  984.         windOrd := theWind.o;
  985.         title := theWind.t;
  986.         if (specifier > 0)
  987.             Str1 := "of ordinality {specifier} ";
  988.         else if (specifier = 0)
  989.             Str1 := "with grow and zoom box ";
  990.         else if( not IsNumber(specifier))
  991.             Str1 := "";
  992.         if (absolutely) begin
  993.             drag [window o:windOrd t:title]! a:{h,v};                        #To drag the window
  994.             str := "Dragged window {Str1}titled '{title}' to absolute location {h},{v}";
  995.         end;
  996.         else begin
  997.             drag [window o:windOrd t:title]! r:{h,v};                        #To drag the window
  998.             str := "Dragged window {Str1}titled '{title}' {h} pixels horizontally and {v} pixels vertically";
  999.         end;
  1000.         LogStr(str);
  1001.         return(1);
  1002.     end; 
  1003.     # Error messages
  1004.     else begin
  1005.         if (specifier > 0)
  1006.             Str1 := "!@#$% There was no window of ordinality {specifier} to drag";
  1007.         else if (specifier = 0)
  1008.             Str1 := "!@#$% Couldn't find window with grow and zoom box to drag";
  1009.         else if( not IsNumber(specifier))
  1010.             Str1 := "!@#$% There was no window titled '{specifier}' to drag";
  1011.     end;
  1012.     
  1013.     LogStr(Str1);
  1014.     return(0);
  1015. end;  # DragWindow()
  1016.  
  1017.  
  1018. #########################################################################
  1019. #                    SizeWindow(X,Y,specifier,absolutely)
  1020. #========================================================================
  1021. # Author:        KTA
  1022. # Description:    This routine will match and resize the specified window.
  1023. #                If only the X and Y parameters are passed, the default
  1024. #                behavior will size the first window containing a grow
  1025. #                and zoom box absolutely.  If no parameters are passed,
  1026. #                then the default behavior will generate random
  1027. #                coordinates on the main screen and resize the window
  1028. #                to an absolute size.  If the user passes in the string
  1029. #                "random" for x and y and passes 0 for the absolutely
  1030. #                parameter (for a resize relative to current size),
  1031. #                then checks are performed to assure that new size will
  1032. #                not go off of the screen.  If it does, the values will
  1033. #                be adjusted so that the largest the window can be sized
  1034. #                is to the border of the screen.
  1035. # Parameters:    X,Y -    the Width and Height to resize the window
  1036. #                specifier -    title or ordinality of window to be sized
  1037. #                absolutely -    1 if resize window absolute
  1038. #                                0 if resize window relative
  1039. # Returns:        1 - Resized window OK
  1040. #                0 - Couldn't resize window
  1041. # Examples:        SizeWindow(200,400);
  1042. #     Note:        #### The Zoom and the Grow trait are matched!!! 
  1043. #                Some Apps don't work if just the g: trait is used.
  1044. #========================================================================
  1045. # History:
  1046. #     NJV        11/20/89    Created    
  1047. #    KTA        1/20/90        Implemented LogStr()
  1048. #    NJV        4/26/90        Added byOrdinality, value, and absolutely parameters
  1049. #    NJV        5/14/90        Condensed byOrdinality and value into specifier parameter
  1050. #    NJV        5/15/90        Added random function
  1051. #    NJV/KTA    7/13/90        Bug fix - only checks window for zoom box under default
  1052. #    NJV        7/19/90        Cut routine size in half.
  1053. #    DM        9/27/90        Optimized and added FindWindow
  1054. #                        Changed specifier default to 0 so it will match the 
  1055. #                        first document window.
  1056. #########################################################################
  1057. task SizeWindow(x:="random", y:="random", specifier := 0, absolutely := 1) begin
  1058.     randomFlag := 0;
  1059.     if (x = "random") begin    # user wants to size window randomly
  1060.         xyRandom := getXYRandom(,-1);
  1061.         x := xyRandom[1];
  1062.         y := xyRandom[2];
  1063.         randomFlag := 1;
  1064.         if (not absolutely) begin        # relative - include possible negative values
  1065.             negative := random(0,1);
  1066.             if (negative = 1) begin
  1067.                 x := 0 - x;
  1068.                 y:= 0 - y;
  1069.             end;
  1070.         end;
  1071.     end;
  1072.     
  1073.     theWind := FindWindow(specifier);
  1074.     specifier := theWind.o;
  1075.     title := theWind.t;
  1076.         
  1077.     # specifier = ordinality of window to size
  1078.     # title = title of window to size
  1079.     if randomFlag begin        # make sure if random numbers were generated that new window size is on screen
  1080.         theWindRect := theWind.r;
  1081.         match [screen r:?theScrnRect]!;
  1082.         if (absolutely) begin    # get Top-Left corner coord of window
  1083.             if ((theWindRect[1] + x) > theScrnRect[3])        # x value off of screen - adjust it
  1084.                 x := theScrnRect[3] - theWindRect[1];
  1085.             if ((theWindRect[2] + y) > theScrnRect[4])        # y value off of screen - adjust it
  1086.                 y := theScrnRect[4] - theWindRect[2];
  1087.         end;
  1088.         else begin                # size window relative - get Bottom-Right coord of window
  1089.             if (not negative) begin
  1090.                 if ((theWindRect[3] + x) > theScrnRect[3])        # x value off of screen
  1091.                     x := theScrnRect[3] - theWindRect[3];
  1092.                 if ((theWindRect[4] + y) > theScrnRect[4])        # y value off of screen
  1093.                     y := theScrnRect[4] - theWindRect[4];
  1094.             end;
  1095.             ### the 20 in the equations below must be there.  This is to assure that
  1096.             ### the window is not sized below 20 horizontally (the size box is 20 pixels,
  1097.             ### and attempts to size smaller than that will cause VU to display an
  1098.             ### "Out of bounds" error.
  1099.             else begin        # negative value - must check against upper-left corner of screen
  1100.                 if ((theWindRect[3] + x - 20) < theScrnRect[1])        # x value off of screen
  1101.                     x := 20 - theWindRect[3] - theScrnRect[1];
  1102.                 if ((theWindRect[4] + y - 20) < theScrnRect[2])        # y value off of screen
  1103.                     y := 20 - theWindRect[4] - theScrnRect[2];
  1104.             end;
  1105.         end;
  1106.     end;
  1107.     if (absolutely) begin
  1108.         size [window t:title o:specifier g:true ] W:x H:y;                        #To size the window
  1109.         match [window t:title o:specifier g:true r:?theWindRect]!;
  1110.         x := theWindRect[3] - theWindRect[1];
  1111.         y := theWindRect[4] - theWindRect[2];
  1112.         str := "Resized window '{title}' absolute {x} pixels wide and {y} pixels high";
  1113.     end;
  1114.     else begin
  1115.         if (randomFlag)    begin            # include negative offsets for random size
  1116.             match [window t:title o:specifier g:true r:?theOrigWindRect]!;
  1117.  
  1118.             size [window t:title o:specifier g:true ] r:{ x, y };                #To size the window
  1119.  
  1120.             match [window t:title o:specifier g:true r:?theWindRect]!;
  1121.             x := theWindRect[3] - theOrigWindRect[3];
  1122.             y := theWindRect[4] - theOrigWindRect[4];
  1123.         end;
  1124.         else begin
  1125.             size [window t:title o:specifier g:true] r:{ x, y };                        #To size the window
  1126.             match [window t:title o:specifier g:true r:?theWindRect]!;
  1127.             x := theWindRect[3] - x;
  1128.             y := theWindRect[4] - y;
  1129.         end;
  1130.         str := "Resized window '{title}' relative {x} pixels wide and {y} pixels high";
  1131.     end;
  1132.     LogStr(str);
  1133.     return(1);
  1134. end;  # SizeWindow()
  1135. ### Set - No variable definition exists for oldType.
  1136. ### Set - No variable definition exists for oldBack.
  1137. ### Set - No variable definition exists for oldCase.
  1138.  
  1139.  
  1140. #########################################################################
  1141. #                            ZoomWindow(specifier)
  1142. #========================================================================
  1143. # Author:        KTA
  1144. # Description:    Selects the zoom box on the requested window.  If no
  1145. #                parameters are passed, then the default behavior will
  1146. #                zoom the first window with a zoom box.
  1147. # Parameters:    specifier -    holds title or ordinality of window to zoom
  1148. # Returns:        0 - Couldn't zoom the window
  1149. #                1 - Zoomed the window OK
  1150. #========================================================================
  1151. # History:
  1152. #    KTA        3/8/90        Created
  1153. #    NJV        4/7/90        Changed name to ZoomWindow and added title parameter
  1154. #                        to zoom a window by title instead of ordinality 1
  1155. #    NJV        4/9/90        Changed title parameter to byOrdinality and specifier
  1156. #                        to allow window specification by title or ordinality.
  1157. #    NJV        5/13/90        Condensed parameters to a single parameter
  1158. #                        Took out select window call
  1159. #    DM        9/27/90        Optimized and added FindWindow
  1160. #                        Changed specifier default to 0 so it will match the 
  1161. #                        first document window.
  1162. #    NJV        6/25/91        Added check to assure zoom box is on screen
  1163. #########################################################################
  1164. task ZoomWindow(specifier:= 0) begin
  1165.     theWind := FindWindow(specifier);
  1166.     if theWind begin
  1167.         windOrd := theWind.o;
  1168.         title := theWind.t;
  1169.         zoomBox := theWind.z;
  1170.         theRect := theWind.r;                        # njv - added 6/25/91
  1171.         theHitPoint := {theRect[3]-20,theRect[2]};    # hit point for zoom box
  1172.         hitPointOffScreen := false;
  1173.         
  1174.         if (specifier > 0)
  1175.             Str1 := "of ordinality {specifier} ";
  1176.         else if (specifier = 0)
  1177.             Str1 := "with a zoom box ";
  1178.         else if( not IsNumber(specifier))
  1179.             Str1 := "";
  1180.         if (zoomBox) begin
  1181.             # test to see if zoom box is on screen
  1182.             screenList := collect [screen]!;
  1183.             for each item in screenList begin
  1184.                 if not (PtInRect(theHitPoint,item.r))     # see if zoom box on screen
  1185.                     hitPointOffScreen := true;
  1186.             end;
  1187.             if (hitPointOffScreen)    # can't zoom window
  1188.                 str := "Couldn't zoom window {Str1}titled '{title}' - zoom box off screen";
  1189.             else begin                # zoom the window
  1190.                 zoom [window o:windOrd t:title]!;    #To zoom the window
  1191.                 str := "Zoomed window {Str1}titled '{title}'";
  1192.             end;
  1193.         end;
  1194.         else begin
  1195.             str := "No zoom box found in window {Str1}titled '{title}'";
  1196.         end;
  1197.         LogStr(str);
  1198.         return(1);
  1199.     end; 
  1200.     # Error messages
  1201.     else begin
  1202.         if (specifier > 0)
  1203.             Str1 := "!@#$% There was no window of ordinality {specifier} to zoom";
  1204.         else if (specifier = 0)
  1205.             Str1 := "!@#$% Couldn't find window with grow and zoom box to zoom";
  1206.         else if( not IsNumber(specifier))
  1207.             Str1 := "!@#$% There was no window titled '{specifier}' to zoom";
  1208.     end;
  1209.     LogStr(Str1);
  1210.     return(0);
  1211. end;  # ZoomWindow()
  1212.  
  1213.  
  1214. ########################################################################
  1215. #                            ScrollWindow(foo,x,y)
  1216. #=======================================================================
  1217. # Author:        KTA/NJV
  1218. # Description:    This routine will scroll the specified scrollbar on
  1219. #                the active window.  If x and y are not passed, then this
  1220. #                task will randomly scroll the requested scrollbar.
  1221. # Parameters:    foo = 'H' - for horizontal scrollbar
  1222. #                    = 'V' - for vertical scrollbar
  1223. #                <x><y> = the fraction x/y
  1224. # Returns:        0 - Couldn't scroll the scroll bar
  1225. #                1 - Scrolled the scroll bar
  1226. # Examples:        ScrollWindow('H',1,2)  will scroll the horizontal bar 1/2
  1227. # Assumptions:    That the scrollbars are present. This routine collects
  1228. #                only the first two scroll bars, which are assumed to be 
  1229. #                the horizontal and vertical scroll bars. 
  1230. #                This routine is not 100% reliable.
  1231. #=======================================================================
  1232. # History:
  1233. #     KTA/NJV    11/21/89    Created
  1234. #    KTA        1/20/89        Added Scrapbook Support
  1235. #    KTA        1/20/90        Added LogStr call
  1236. #    KTA     5/14/90        Removed scrapbook Support
  1237. #                        Now checks to see if scrolllbars are enabled
  1238. #    NJV        6/25/90        Added random scrolling
  1239. #    NJV        7/5/90        Added GetVHScrollBars call.
  1240. #    NJV        4/1/91        Updated header for default behavior
  1241. #    NJV        6/26/91        Bug fix - enabled scroll bar check now works
  1242. #########################################################################
  1243. task ScrollWindow(foo,x:=-1,y:=-1) begin
  1244.     theScrollBars := GetVHScrollBars();
  1245.     if (not theScrollBars)
  1246.         return(0);        # error - couldn't find scroll bars
  1247.     vertical := theScrollBars[1];
  1248.     verticalDiff := vertical.s;
  1249.     horizontal := theScrollBars[2];
  1250.     horizontalDiff := horizontal.s;
  1251.  
  1252.     if (foo = 'V') or (foo = 'v') begin
  1253.         if (x=-1) or (y=-1) begin    # generate random value
  1254.             x := random(0,verticalDiff[2]);
  1255.             y := verticalDiff[2];
  1256.         end;
  1257.         if (vertical.e) begin        #Test to see if Scrollbars are enabled
  1258.             scroll vertical a:{x,y};
  1259.             LogStr("Scrolled the vertical scroll bar Absolute ({x}, {y})");
  1260.         end;
  1261.         else begin
  1262.              LogStr("!@#$% The vertical scroll bar was not enabled to scroll");
  1263.             return(0);
  1264.         end;
  1265.     end;
  1266.     else begin
  1267.         if (x=-1) or (y=-1) begin    # generate random value
  1268.             x := random(0,horizontalDiff[2]);
  1269.             y := horizontalDiff[2];
  1270.         end;
  1271.         if (horizontal.e) begin        #Test to see if Scrollbars are enabled
  1272.             scroll horizontal a:{x,y};
  1273.             LogStr("Scrolled the horizontal scroll bar absolute ({x}, {y})");
  1274.         end;
  1275.         else begin
  1276.             LogStr("!@#$% The horizontal scroll bar was not enabled to scroll");
  1277.             return(0);
  1278.         end;
  1279.     end;
  1280.     return(1);
  1281. end;  # ScrollWindow()
  1282.  
  1283. ########################################################################
  1284. #                            GetVHScrollBars()
  1285. #=======================================================================
  1286. # Author:            NJV
  1287. # Description:        This routine will return the vertical and horizontal
  1288. #                    scroll bars.
  1289. # Parameters:        None
  1290. # Returns:            0 - Couldn't find scroll bars
  1291. #                    {vertical,horizontal} - list of vertical and horizontal
  1292. #                                            scroll bars
  1293. # Examples:            scrollBars := GetVHScrollBars();
  1294. # Assumptions:        Top of vertical scroll bar is at a lower vertical value
  1295. #                    that the horizontal (i.e. the top of vertical rect is smaller
  1296. #                    than the top of the horizontal scroll bar's rect).
  1297. #=======================================================================
  1298. # History:
  1299. #    NJV        6/25/90        Created
  1300. #########################################################################
  1301. task GetVHScrollBars() begin
  1302.     ScrollWindowlist :=collect[scrollbar];
  1303.     if not (card(ScrollWindowlist)) begin
  1304.         LogStr("!@#$% There were no recognizable scroll bars present");
  1305.         return(0);
  1306.     end;
  1307.     Rec1 := ScrollWindowlist[1];
  1308.     Rec2 := ScrollWindowlist[2];
  1309.     Rec1R := Rec1.r[1];
  1310.     Rec2R := Rec2.r[1];
  1311.  
  1312.     if (Rec1R < Rec2R) begin         #To determine which scroll bar is Vertical/Horizontal
  1313.         horizontal := Rec1;
  1314.         vertical := Rec2;
  1315.     end;
  1316.     else begin
  1317.         horizontal := Rec2;
  1318.         vertical := Rec1;
  1319.     end;
  1320.     return({vertical,horizontal});
  1321. end;
  1322.  
  1323. #########################################################################
  1324. #                CloseWindow(howClose, overwrite, specifier,DocName)
  1325. #========================================================================
  1326. # Author:        KTA/NJV/DMM
  1327. # Description:    This routine will close the specified window.  If no
  1328. #                parameters are passed to this routine, the default behavior
  1329. #                will select the close box of the first window with a close box.
  1330. # Parameters:    howClose -    0 -    tries all three ways noted below to close the
  1331. #                                window (if needed)
  1332. #                            1 -    tries to close window by selecting "Close" menu
  1333. #                                item
  1334. #                            2 -    tries to close window by typing "Close" menu
  1335. #                                item's key equivalent
  1336. #                            3 -    tries to close window by selecting window's
  1337. #                                close box
  1338. #                overwrite -    0 -    will select "No" from a save-changes dialog
  1339. #                                if one appears when closing window
  1340. #                            1 -    will select "Yes" to save changes
  1341. #                specifier -    holds title or ordinality of window to close
  1342. #                DocName -    string holding new document name - if overWrite
  1343. #                            parameter is 1, then DocName will be used for
  1344. #                            naming the file.
  1345. # Returns:        1 - Closed window OK
  1346. #                0 - Couldn't find window to close
  1347. #========================================================================
  1348. # History:
  1349. #    KTA/DM    1/20/90        Created
  1350. #    NJV        4/07/90        Changed name from CloseW() and added title parameter
  1351. #    NJV        4/27/90        Changed to call closeOneWindow and added parameters
  1352. #    NJV        5/13/90        Condensed parameters and added CloseOneWindow in-line
  1353. #    KTA/NJV 7/17/90        Added DocName parameter, updated checkYesNo calls
  1354. #    KTA        8/21/90        Fixed bug in closing by specifier-used to close front window
  1355. #    DM        9/24/90        Fixed error meesage for "No window" case.  Commented out 
  1356. #                        extra(?) match window
  1357. #    DM        9/27/90        Optimized and added FindWindow
  1358. #                        Changed specifier default to 0 so it will match the 
  1359. #                        first document window.
  1360. #    ECH        11/5/90        in howClose 3, closed window using ord and theTitle instead
  1361. #                        of just theTitle in case two windows have the same name
  1362. #    NJV        11/27/90    Addded documentation for DocName
  1363. ###########################################################################
  1364. task CloseWindow(howClose := 3,overwrite := 1,specifier := 0,DocName :="") begin
  1365.  
  1366.     theWind := FindWindow(specifier);
  1367.     
  1368.     if theWind begin
  1369.         ord := theWind.o;
  1370.         theTitle := theWind.t;
  1371.         if (ord <> 1)
  1372.             SelectWindow(ord);
  1373.  
  1374.         if (not howClose)
  1375.             tryAll := 1;
  1376.         else
  1377.             tryAll := 0;
  1378.             
  1379.         if (howClose = 1 or tryAll) begin
  1380.             if match [menuItem t: "Close" e: TRUE]! begin
  1381.                 SelectMenuItem("Close","File");
  1382.                 checkYesNo(overwrite,DocName);
  1383.                 return(1);
  1384.             end;
  1385.             else if not tryAll
  1386.                 return(0);
  1387.         end;
  1388.     
  1389.         if (howClose = 2 or tryAll) begin
  1390.             closeKey := match[menuItem t:"Close"];
  1391.             if (closeKey.k) begin
  1392.                 KeyEq(closeKey.k);
  1393.                 if (global AppVerify)
  1394.                     MatchApp(0);    #In case or DAs are closed - verifies application
  1395.                 str := "Typed key-equivalent to close window titled '{theTitle}'";
  1396.                 LogStr(str);
  1397.                 checkYesNo(overwrite,DocName);
  1398.                 return(1);
  1399.             end;
  1400.             else if not tryAll
  1401.                 return(0);
  1402.         end;
  1403.             
  1404.         if (howClose = 3 or tryAll) begin
  1405.             frontWindow := match[window o:ord t:theTitle c:true]!;
  1406.             if (frontWindow) begin
  1407.                 close [window o:ord t:theTitle c:true]!;
  1408.                 checkYesNo(overwrite,DocName);
  1409.                 if (global AppVerify)
  1410.                     MatchApp(0);    #In case DAs are closed - verifies application
  1411.                 str := "Selected the Close Box on window titled '{theTitle}'";
  1412.                 LogStr(str);
  1413.                 return(1);
  1414.             end;
  1415.         end;
  1416.  
  1417.         if (tryAll)
  1418.             LogStr("!@#$% Couldn't close window by 'Close' menu item, close box, or keyboard equivalent");
  1419.         else
  1420.             LogStr("!@#$% There is no Close Box Available ");
  1421.         return(0);
  1422.     end;
  1423.     else begin
  1424.         if (IsNumber(specifier))    # ordinality
  1425.             if (specifier <> 0)
  1426.                 str := "!@#$% Couldn't find window of ordinality {specifier} to close";
  1427.             else
  1428.                 str := "No windows to close";
  1429.         else
  1430.             str := "!@#$% Couldn't find window '{specifier}' to close";
  1431.         LogStr(str);
  1432.         return(0);
  1433.     end;
  1434. end; # CloseWindow()
  1435.  
  1436.  
  1437. #########################################################################
  1438. #             MoveRelativeToWindow(x, y, specifier,mouseDown,inset)
  1439. #========================================================================
  1440. # Author:        NJV
  1441. # Description:    This routine will calculate the window's rectangle
  1442. #                and add x and y input parameters to the 
  1443. #                rectangle's top-left coordinate point.  It will then
  1444. #                move the mouse to that location.  The window is
  1445. #                specified by the specifier input parameter.  If the
  1446. #                specifier parameter is not present, the default
  1447. #                behavior will move relative to the frontmost window.
  1448. # Parameters:    x - int representing left (x) coord
  1449. #                y - int representing top (y) coord
  1450. #                specifier - holds title or ordinality of window
  1451. #                            0 matches first s:document c:true g:true window
  1452. #                mouseDown - 0 - don't hold mouse key down while moving
  1453. #                            1 - press mouse key down - move - release
  1454. #                            2 - Click after moving - no mouse down during move
  1455. #                            3 - press mouse key down - move - don't release
  1456. #                            4 - move - release
  1457. #                inset    -   inset from window rect for GetXYRandom
  1458. # Returns:        Nothing
  1459. # Examples:        MoveRelativeToWindow(12,25);
  1460. # Assumptions:    Assumes there is a window on the screen 
  1461. #========================================================================
  1462. # History:
  1463. #     NJV        10/2/89        Created
  1464. #    NJV        5/13/90        Changed thePoint parameter to two parameters (x, y)
  1465. #    NJV        5/22/90        Added specifier parameter
  1466. #    NJV        7/5/90        Added mouseDown and mouseUp parameters for MoveMouse
  1467. #    NJV        7/9/90        Added matchTarget parameter for diabling target matching
  1468. #    KTA        7/17/90        Added MouseDown = 2 - click after move
  1469. #    NJV        7/17/90        Took out matchTarget and mouseUp parameters
  1470. #    DM        9/24/90        Added inset param so it can be passed to GetXYRandom.
  1471. #                        Added 0 option for specifier so it will match the 
  1472. #                        first document window.
  1473. #    DM        9/27/90        Optimized and added FindWindow
  1474. #########################################################################
  1475. task MoveRelativeToWindow(x:= 'random', y, specifier:=1,mouseDown:=0,inset:= {30,30,30,30}) begin
  1476.     if ( x='random') begin    # user wants random mouse move
  1477.         xyRandom := GetXYRandom(inset, specifier);
  1478.         x := xyRandom[1];
  1479.         y := xyRandom[2];
  1480.     end;
  1481.     theWind := FindWindow(specifier);
  1482.     if theWind begin
  1483.         lvWindRect := theWind.r;
  1484.         lvX := lvWindRect[1];                # X = LEFT (the X co-ord)
  1485.         lvY := lvWindRect[2];
  1486.         lvFinalLeft := x + lvX;        # calculate absolutely X
  1487.         lvFinalTop := y + lvY;            # calculate absolutely Y
  1488.         MoveMouse(lvFinalLeft,lvFinalTop,1,mouseDown);    # move to the calculated location
  1489.         finalVal := {lvFinalLeft,lvFinalTop};
  1490.         return finalVal;
  1491.     end;
  1492.     else begin
  1493.         if (specifier > 0)
  1494.             Str1 := "!@#$% Couldn't find a window of ordinality {specifier}";
  1495.         else if (specifier = 0)
  1496.             Str1 := "!@#$% Couldn't find a window with grow and zoom box";
  1497.         else if( not IsNumber(specifier))
  1498.             Str1 := "!@#$% Couldn't find a window titled '{specifier}'";
  1499.     end;        
  1500. end; # MoveRelativeToWindow()
  1501.  
  1502.  
  1503. #########################################################################
  1504. #                 MoveMouse(x, y, absolutely, mouseDown)
  1505. #========================================================================
  1506. # Author:        DMM
  1507. # Description:    This routine will move the mouse x,y relative to
  1508. #                it s current location.  If x and y are absent or
  1509. #                equal to "random", a random move is generated.
  1510. # Parameters:    absolutely - 1 if move absolutely, 0 if relative
  1511. #                x         x distance to move mouse
  1512. #                y         y distance to move mouse
  1513. #                        if x and y are absent or := "random" then a 
  1514. #                        random move is generated
  1515. #                absolutely    -    1 to move to absolute location
  1516. #                                0 to move relative to current location
  1517. #                mouseDown - 0 - don't hold mouse key down while moving
  1518. #                            1 - press mouse key down - move - release
  1519. #                            2 - Click after moving - no mouse down during move
  1520. #                            3 - press mouse key down - move - don't release
  1521. #                            4 - move - release
  1522. # Returns:        Nothing
  1523. #========================================================================
  1524. # History:
  1525. #    DM        4/19/90        Created
  1526. #    NJV        4/26/90        Changed to allow for relative or absolutely moving
  1527. #    NJV        5/13/90        Re-ordered parameters
  1528. #    NJV        7/5/90        Added mouseUp parameter (defaults to original behavior)
  1529. #    NJV        7/5/90        Changed 2 LogStr calls to 1.
  1530. #    NJV        7/9/90        Added matchTarget parameter (LogStr disables target if mouseDown)
  1531. #    KTA        7/17/90        Added MouseDown = 2 - click after move
  1532. #    NJV        7/17/90        Took out matchTarget parameter - used mouseDown and mouseUp
  1533. #    NJV        7/17/90        Took out mouseUp parameter - changed possible values for mouseDown
  1534. #########################################################################
  1535. task MoveMouse(x := 'random', y := 'random', absolutely := 1, mouseDown := 0)
  1536. begin
  1537.     if ( x='random') begin    # user wants random mouse move
  1538.         xyRandom := getXYRandom();
  1539.         x := xyRandom[1];
  1540.         y := xyRandom[2];
  1541.     end;
  1542.     
  1543.     if ((mouseDown = 1) or (mouseDown = 3))
  1544.         pressMouse;
  1545.     
  1546.     if (absolutely) begin
  1547.         move a: { x, y };
  1548.         str := "Moved the mouse to absolute location ∂({x},{y}∂)";
  1549.     end;
  1550.     else begin
  1551.         move r: { x, y };
  1552.         str := "Moved the mouse relative ∂({x},{y}∂) to previous position";
  1553.     end;
  1554.     
  1555.     # release mouse if needed
  1556.     if ((mouseDown = 1) or (mouseDown = 4))
  1557.         releaseMouse;
  1558.  
  1559.     # add mouse down to log string if needed
  1560.     if ((mouseDown = 1) or (mouseDown = 3) or (mouseDown = 4))
  1561.         str := "{str} with mouse button held down";
  1562.     
  1563.     # click if needed
  1564.     if (mouseDown = 2 ) begin
  1565.         Click;
  1566.         str := "{str} and clicked";
  1567.     end;
  1568.     
  1569.     # log it
  1570.     LogStr(str);    
  1571. end; # MoveMouse()
  1572.  
  1573. ########################################################################
  1574. #                     DrawShapeFrame(specifier := 1,ltrb)                        
  1575. #=======================================================================
  1576. # Author:         DMM                        
  1577. # Description:    Click drags a rectangular frame in the specified window.                                            
  1578. # Parameters:    specifier    window to draw in; defaults to ordinality 1            
  1579. #                ltrb         {"random"} or {l,t,r,b} of rect to draw 
  1580. #                inset         defines the drawing area relative to the 
  1581. #                            window rectangle
  1582. # Returns:        nada
  1583. #=======================================================================
  1584. # History:
  1585. # DM        5/22/90        created
  1586. # DM        9/24/90        Use GetXYRandom to get coords, change
  1587. #                        ltrb param to a list.  Addd inset param
  1588. #                        so it can be passed to GetXYRandom.
  1589. # DM        9/24/90        Generalized and rolled into control.lib
  1590. #########################################################################
  1591. task DrawShapeFrame(spec := 1,ltrb := {"random"},inset := {0,0,0,0}) begin
  1592.     
  1593.     if (ltrb[1] = "random") begin
  1594.         lrel := "random";
  1595.         rRel := "random";
  1596.     end;
  1597.     else begin
  1598.         lRel := ltrb[1];
  1599.         tRel := ltrb[2];
  1600.         rRel := ltrb[3];
  1601.         bRel := ltrb[4];
  1602.     end;
  1603.     temp := global DisableAllLogging;
  1604.     global DisableAllLogging := 1;
  1605.     mTemp := mouseSpeed(10);
  1606.     lT := MoveRelativeToWindow(lRel,tRel,spec,0,inset);
  1607.     rB := MoveRelativeToWindow(rRel,bRel,spec,1,inset);
  1608.     mouseSpeed(mTemp);
  1609.     global DisableAllLogging := temp;
  1610.     left := lT[1]; top := lT[2]; right := rB[1]; bott := rB[2];
  1611.     LogStr("Click-Dragged frame from ∂({left},{top}∂) to ∂({right},{bott}∂).");
  1612. end;
  1613.  
  1614. #########################################################################
  1615. #                        NameOK(NameDoc, replaceFlag)
  1616. #========================================================================
  1617. # Author:        KTA
  1618. # Description:    This routine will type a name (NameDoc) into the text edit
  1619. #                field.  Then it will press the ReturnKey. If there is a
  1620. #                document already named <NameDoc> then this task will check
  1621. #                the replaceFlag.  If it is defined as anything but true
  1622. #                it will select NO to 'Replace Existing?' dialog. It will
  1623. #                then type the time (based on a 24 hour clock) after the
  1624. #                name and retype the ReturnKey. The Default is to replace
  1625. #                an existing document with the same name. It will also call
  1626. #                getNewFileName to create a file name if one is not provided.
  1627. # Parameters:    NameDoc - string holding the name to name the document
  1628. #                replaceFlag - 0 to select 'No' to 'Replace Existing' dialog
  1629. #                              1 to select 'Yes' to replace existing file.
  1630. # Returns:        string - filename of saved document
  1631. # Examples:        NameOk('Untitled1'); to name the file 'Untitled1'
  1632. # Assumptions:    That the SF_Put dialog is present
  1633. #                 A call to SelectMenuItem('Save As', 'File'); should probably
  1634. #                be made prior to calling NameOK()
  1635. #========================================================================
  1636. # History:
  1637. #     KTA        11/20/89    Created
  1638. #    KTA     5/17/90        Added Global LastSavedFile;
  1639. #    KTA     6/1/90        Fixed so that the time will be appended in 7.0
  1640. #    NJV        6/26/90        Returns filename
  1641. #    KTA     7/13/90     Remove Return 0 if no 'Yes' Button
  1642. #    NJV        7/27/90        Will keep renaming until original filename
  1643. #    KTA        8/2/90        Matches for a dialog
  1644. #    KTA        8/22/90        DisableAllLogging after matching for dialog once.
  1645. #    NJV        11/27/90    Updated documentation for replaceflag.
  1646. #    KTA        12/20/90    Updated for  7.0ß2+ - changes to dialog 
  1647. #    KTA        2/25/91        Better check for SF Dialog
  1648. #########################################################################
  1649. task NameOK(NameDoc := "", replaceFlag := true) begin
  1650.     temp := global DisableAllLogging;
  1651.     if (NameDoc = "") begin
  1652.         nameDoc := GetNewFileName();    #To get a name    #
  1653.     end;
  1654.     For SFCheck := 1 to 5 begin 
  1655.         DialogWin := match[window o:1 s:dialog]!;
  1656.         if (DialogWin)
  1657.              SFCheck := 5;
  1658.         else
  1659.             LogStr('There is no SF_PUT dialog to name the document with');
  1660.         if (SFCheck = 5) and not (DialogWin)
  1661.             Return(0);
  1662.     end;
  1663.     DisableAllLogging :=Temp;
  1664.     typeStr("{NameDoc}");
  1665.     SpecialKey(returnKey, 'Return Key');
  1666.     wait(2);
  1667.     Foo := Match[window s:Dialog o:1];
  1668.     ButtonName :='';
  1669.     while Foo begin
  1670.         foo := Match[button t:'Yes']!;
  1671.         if foo 
  1672.             ButtonName := Foo.t;
  1673.         else  begin
  1674.             foo := Match[button t:'Replace']!;
  1675.             ButtonName := Foo.t;
  1676.         end;
  1677.         if (replaceFlag) and (ButtonName) begin    #Want to replace
  1678.             SelectButton(ButtonName);
  1679.         end;
  1680.         else begin        #Don't want to replace
  1681.             if (ButtonName = "Replace") #If match 'Replace' button but don't want to replace select 'Cancel'
  1682.                 ButtonName := "Cancel";
  1683.             else  if (ButtonName = "Yes") begin
  1684.                 ButtonName := "No"; #If match 'Yes' button but don't want to replace select 'No'
  1685.             end;
  1686.             if ButtonName begin
  1687.                 SelectButton(ButtonName);
  1688.                 x := GetNewFileName(nameDoc);
  1689.                 type k:{ rightArrowKey };    #This is so the time will 
  1690.                 TypeStr("{x}");                #be appended in 6.0/7.0
  1691.                 SpecialKey(returnKey, 'Return key');
  1692.             end;
  1693.             namedoc := namedoc + "{x}";
  1694.         end;
  1695.         if ButtonName
  1696.             foo := Match[button t:ButtonName]!;
  1697.     end;
  1698.  
  1699.     LogStr("The documents final name is {namedoc}");
  1700.     global LastSavedFile := namedoc;
  1701.     return(namedoc);
  1702. end; # NameOK()
  1703.  
  1704. #########################################################################
  1705. #                            GetNewFileName(name)    
  1706. #========================================================================
  1707. # Author:        SL
  1708. # Description:    Gets a new file name by concatenating the app name and
  1709. #                the current time.
  1710. # Parameters:    name -    If this parameter is present, this routine will
  1711. #                        only pass back the time.  If this parameter is not
  1712. #                        present, then this routine will pass back a string
  1713. #                        consisting of the application name with the time
  1714. #                        appended to it.
  1715. # Returns:        newFileName - string name for new file name
  1716. #========================================================================
  1717. # History:
  1718. #    SL        4/3/90        Created
  1719. #    KTA/DM    4/25/90     Reworked the whole thing
  1720. #    KTA        8/17/90        Added default parameter so wouldn't recieve error message
  1721. #########################################################################
  1722. task GetNewFileName(name :="") begin
  1723.     match [time h:?Tm];
  1724.     if not(name = "")
  1725.         newFileName := " {Tm}";
  1726.     else begin
  1727.         match [Application t:?appName];
  1728.         newFileName := "@{appName}-{Tm}";
  1729.     end; # getNewFileName()
  1730.     return(newFileName);
  1731. end; # GetNewFileName()
  1732.  
  1733.  
  1734. #########################################################################
  1735. #                        OpenDoc(namedoc,SelectOpen)
  1736. #========================================================================
  1737. # Author:        KTA
  1738. # Description:    This routine will select 'Open' from the 'File' menu, type
  1739. #                the string held in the nameDoc parameter, and
  1740. #                then press the returnkey.  It will check to see that
  1741. #                the frontmost window's title contains namedoc.  If not,
  1742. #                it assumes that the wrong file opened.  It will not select
  1743. #                'Open' if the SelectOpen parameter is 0.
  1744. # Parameters:    namedoc - string name of document to open
  1745. #                SelectOpen - 0 to disable selecting of the 'Open' menu item.
  1746. #                             1 to select 'Open' from the 'File' menu
  1747. # Returns:        1 - Document opened OK
  1748. #                0 - Document not opened OK
  1749. # Assumptions:    Works with SF_Get, but don't have NameDoc be to long
  1750. #                of a string.
  1751. # Examples:        OpenDoc('Untit'); will select a document such as 'Untitled'.
  1752. #========================================================================
  1753. # History:
  1754. #    KTA        3/16/90        Created
  1755. #    KTA        4/25/90        Changed SelectMenuItem to support by name
  1756. #    NJV        6/26/90        Checks to see if window opened is desired window
  1757. #                        Added return values
  1758. #    DMM        6/28/90        Accounted for no window open
  1759. #    KTA        9/4/90        Added SelectOpen 
  1760. #    NJV        11/27/90    Updated documentation for SelectOpen.
  1761. #########################################################################
  1762. task OpenDoc(namedoc, SelectOpen :=1) begin    
  1763.     global LastSavedFile;
  1764.     if (SelectOpen) begin
  1765.         selectmenuItem("Open", "File");            #To Select the Open MenuItem
  1766.         wait(2);
  1767.     end;
  1768.     TypeStr(nameDoc);                    #To Type the documents name (Shouldn't be to long )
  1769.     SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK' to Revert
  1770.     wait(3);
  1771.     
  1772.     x := match[window g:true z:true t:?DocName]!;;        #To match the document window
  1773.     #To match the top window (Hopefully the Document that was just opened)
  1774.     if (not x) begin
  1775.         LogStr("!@#$% No open window with grow and zoom boxes");
  1776.         return(0);        # no open windows - bad
  1777.     end;
  1778.     LogStr("The front document is named '{DocName}'.");
  1779.     if (isSubString(namedoc,DocName))        # looks like the right file
  1780.         return(1);                            # return O'TAY BUCKWHEAT
  1781.     else begin
  1782.         LogStr("!@#$% It appears that the wrong file was opened, BuckWheat"); 
  1783.         return(0);                                # nope, wrong file
  1784.     end;
  1785. end;  # OpenDoc()
  1786.  
  1787.  
  1788. #########################################################################
  1789. #########                        Twitcher 7.31                #############
  1790. #########################################################################
  1791. # This task is intended to select apps from the Process List menu in System 7.0.
  1792. # If the target is using System 7.0 and numIterations is greater than 0 
  1793. # it will test Showing, Hiding and twitching to all open apps and the Finder.
  1794. # Unless there is a specific need for this task, this task should be used
  1795. # only by LaunchTwitch.  Use LaunchTwitch to handle launching or twitching
  1796. # applications.
  1797.  
  1798. #########################################################################
  1799. #                 Twitcher(appName, numIterations, waitTime)    
  1800. #========================================================================
  1801. # Author:         DM
  1802. # Description:    This routine selects apps from the Process List.
  1803. #                 If numiterations > 0 it will: 
  1804. #                    • selects the app
  1805. #                    • selects Hide Others
  1806. #                    • selects the Finder
  1807. #                    • selects the same app
  1808. #                    • selects Hide app
  1809. #                    • selects Show All
  1810. #                    • selects the next app
  1811. #                for each app in the list.
  1812. # Parameters:        appName - app to twitch to after numIterations thru list
  1813. #                    numIterations -    number of times to go thru the whole list.
  1814. #                        Valid under System 7.0 only!!
  1815. #                     waitTime  - amount of time to wait for twitch to occur. Try
  1816. #                            inserting a wait time if you are experiencing match
  1817. #                            errors. 0 works well with a fx host and a SE30 target.
  1818. # Returns:            0 if twitching to appName fails
  1819. # Examples:            Twitcher("MacWrite 5.0", 5, 0);
  1820. # Assumptions:        None
  1821. #========================================================================
  1822. # History
  1823. #     DMM            5/29/90        created
  1824. #     DMM            6/26/90        streamlined and updated for a11
  1825. #     DMM/KTA        7/31/90        Single twitch and 6.0 compat
  1826. #     KTA            12/20/90    Made the Hide check !
  1827. #########################################################################
  1828. task Twitcher(appName := "", numIterations := 0, waitTime := 0) begin
  1829.     menuOrd :=1;
  1830.     if (Global isSys7) begin
  1831.         match[menuItem t:"Hide Others" m:[menu o:?menuOrd] ]!;
  1832.         if(numIterations) begin
  1833.             itemList := collect[menuItem m:[menu o:menuOrd]];# load list
  1834.             numItems := card(itemList);
  1835.             menuSelections := {"{theApp}","Hide Others",'Finder',"{theApp}","Hide {theApp}","Show All"};
  1836.                         
  1837.             for i := 1 to numIterations begin
  1838.                 LogStr("Starting iteration {numIterations}");
  1839.                 for item := 5 to numItems begin
  1840.                     theApp := itemList[item].t;
  1841.                     if theApp <> 'Finder' begin
  1842.                         for each thing in menuSelections begin
  1843.                             selectMenuItem(/{thing}≈/);
  1844.                             wait(waitTime);
  1845.                         end;
  1846.                     end;
  1847.                 end;
  1848.             end;
  1849.         end;
  1850.     end;
  1851.     
  1852.     y := match[menuItem t:/≈{appName}≈/ m:[menu o:menuOrd] ]!;
  1853.     #y := match[menuItem t:/¬"Hide"≈{appName}≈/ m:[menu o:menuOrd] ]!;
  1854.     if y begin
  1855.         if not(y.t = /Hide≈/!) begin
  1856.             select y;
  1857.             AppName := y.t;
  1858.             LogStr("Selected menuItem {AppName} from the process list");
  1859.             wait(2);
  1860.             matchApp(1);
  1861.             return(1);
  1862.         end;
  1863.     end;
  1864.     else begin
  1865.         LogStr("Sorry Charlie, Couldn't select {appName} from the process list");
  1866.         return 0;
  1867.     end;
  1868. end;
  1869.  
  1870. #########################################################################
  1871. #                MiniLaunch(appTitle, LaunchApp, SetDir)
  1872. #========================================================================
  1873. # Author:        NJV - DMM
  1874. # Description:    This routine will launch an application on the target
  1875. #                machine(s).  The miniLauncher tool should be the running
  1876. #                application on the target machine(s).  This routine will
  1877. #                type the input parameter appTitle to the target machine
  1878. #                and then type the return key (which is how an application
  1879. #                is launched using miniLauncher.)  The application to be
  1880. #                launched must reside in a folder beneath the miniLauncher
  1881. #                tool in the directory hierarchy. For more information on
  1882. #                the miniLauncher tool, see the Read-Me that accompanies
  1883. #                the tool.  MiniLauncher can be found on the
  1884. #                De Anza 6/2nd:SIAC Server:Backup Stuff:VU Heads:MiniLauncher
  1885. #                MiniLauncher can also open or print documents.  See the
  1886. #                LaunchApp parameter description below for more details.
  1887. #
  1888. # Parameters:    appTitle -    title of the application or document to be launched.
  1889. #                            The title does not have to be complete.  The MiniLauncher
  1890. #                            tool will launch the first application it finds
  1891. #                            starting with the string appTitle.  If LaunchApp
  1892. #                            parameter is not 1, then appTitle will hold the
  1893. #                            document name to be opened or printed.
  1894. #                LaunchApp - 1 to launch application
  1895. #                            0 to launch application via a document
  1896. #                            -1 to print a document (launch app and print)
  1897. #                SetDir    -    1 to set the default directory to that of the
  1898. #                                application
  1899. #                            0 to bypass setting of default directory (will
  1900. #                                end up being MiniLauncher's directory).
  1901. #
  1902. # Returns:        1 - Launched OK
  1903. #                0 - Couldn't launch application (usually due to lack of 
  1904. #                        enough memory on the target machine).
  1905. #
  1906. # NOTE:        Unless there is a specific reason for using this task, the
  1907. #            scriptor should use LaunchTwitch instead to make the script
  1908. #            independent of the operating system.  This task is used
  1909. #            by LaunchTwitch.
  1910. #
  1911. # Examples:        MiniLaunch('Word');
  1912. #========================================================================
  1913. # History:
  1914. #     NJV-DMM    6/21/90        Created
  1915. #    NJV        11/27/90    Updated for MiniLauncher v.1.3b - added LaunchApp
  1916. #                        and SetDir paramters
  1917. #########################################################################
  1918. task MiniLaunch(appTitle, LaunchApp := 1,SetDir := 1) begin
  1919.     match [application t:?thisAppTitle]!;
  1920.     nextAppTitle := thisAppTitle;
  1921.     
  1922.     # if LaunchApp is 0 check for newest version of MiniLauncher
  1923.     foo := match [button t:'Options']!;
  1924.     if (LaunchApp <> 1) begin
  1925.         if (not foo) begin
  1926.             if (LaunchApp = -1)  # user trying to print document
  1927.                 LogStr("Wrong version of MiniLauncher for printing documents - use v1.3b or newer.");
  1928.             else
  1929.                 LogStr("Wrong version of MiniLauncher for launching documents - use v1.3b or newer.");
  1930.         end;
  1931.         else
  1932.             SelectButton('Options');
  1933.         if (LaunchApp = -1)    # user wants to print document
  1934.             SelectRadioButton('Print Document');
  1935.         else
  1936.             SelectRadioButton('Open Document');
  1937.         
  1938.         SelectButton("OK");
  1939.     end;
  1940.     else if (foo) begin
  1941.         SelectButton('Options');
  1942.         SelectRadioButton('Launch Application');
  1943.         if (SetDir)
  1944.             SelectRadioButton("Application∂'s Directory");
  1945.         else
  1946.             SelectRadioButton("MiniLauncher∂'s Directory");
  1947.         SelectButton('OK');
  1948.     end;
  1949.     
  1950.     type k:{"{appTitle}",returnKey};
  1951.     while (thisAppTitle = nextAppTitle) begin
  1952.         if (match [staticText t:/≈An error has occurred≈/]!) begin
  1953.             type k:{returnKey};
  1954.             return(0);        # application did not launch
  1955.         end;
  1956.         match [application t:?thisAppTitle]!;
  1957.     end;
  1958.     MatchApp(0);
  1959.     LogStr("Launched {thisAppTitle}");
  1960.     return(1);
  1961. end;
  1962.  
  1963.  
  1964. #########################################################################
  1965. #            LaunchTwitch(AppName, Folder, LaunchApp, SetDir)
  1966. #========================================================================
  1967. # Author:        KTA
  1968. # Description:    This routine determines whether the Operating system is 
  1969. #                6.0x or 7.0x and launches the application accordingly.  
  1970. #                6.0x -  Will check the Apple menu to see if the App is 
  1971. #                currently running and select it if it is. If it is not running
  1972. #                it will select MiniLauncher from the Apple menu and call
  1973. #                MiniLaunch(AppName);
  1974. #                7.0x -  Will check the ProcessList to see if the App is 
  1975. #                currently running and select it if it is.  if it is not it will
  1976. #                Select the Apple from the Apple Menu, or the <Folder> and then type
  1977. #                the <AppName> and select the Open menuItem.
  1978. # Parameters:    AppName - Application to be launched/Twitched
  1979. #                Folder -  Folder in the Apple menu that contains <AppName>.
  1980. #                LaunchApp - 0    if AppName is name of a document and not an
  1981. #                                application (for launching app by document
  1982. #                                via MiniLauncher under 6.0.x)
  1983. #                            1    if AppName is name of application to launch
  1984. #                SetDir -    0    will not set directory when launching a directory
  1985. #                            1    will set directory to application's directory
  1986. #                    NOTE: This option is not used unless LaunchApp parameter is 1.
  1987. # Returns:        0 - App did not launch
  1988. #                1 - App launched fine
  1989. #                2 - App launched with minimum memory
  1990. # Examples:        LaunchTwitch('MacWrite', "#CoreAliases");
  1991. #                LaunchTwitch('MacWrite Doc',"#CoreAliases",0);
  1992. # Assumptions:    6.0x -  MiniLauncher is a running application
  1993. #                7.0x -  That the Application (or Alias) is resident in the 
  1994. #                Apple Menu or the <Folder> which contains <AppName> is.
  1995. #========================================================================
  1996. # History:
  1997. # KTA        7/31/90        Created
  1998. # KTA        8/2/90        Added- if not( CurrApp.t ~= /≈{AppName}≈/)
  1999. # DM        9/23/90        Added- Timer()
  2000. # NJV        11/27/90    Added LaunchApp and SetDir parameters
  2001. # KTA        12/10/90    Added-match /≈{Folder}≈/ instead of "{Folder}"
  2002. # KTA        12/17/90    Added-match Check for error dialogs
  2003. # NJV/KTA    12/18/90    Added-BailFlag
  2004. # KTA        12/20/90    LaunchApp     1 - for 7.0 Finder launch on
  2005. #                                    0 - Finder launch off
  2006. # KTA        1/8/90        Removed Timer()
  2007. # KTA        1/9/90        Changed Exits to Return(0)
  2008. # NJV        1/23/91        Returns 1 if app launch OK, 2 if launch in min mem
  2009. # NJV        1/27/91        Disables Integration Module
  2010. # KTA        2/5/91        Changes loop 10 times to loop 2 times
  2011. # KTA        2/24/91        Reset Global AppVerify befroe returning values - bug
  2012. # KTA        2/25/91        /≈{Folder}≈/ to see if correct folder is open
  2013. # KTA        2/25/91        DialogCheck for memory.
  2014. # NJV        3/27/91        Added check for 6.x to see if MiniLauncher is 
  2015. #                        current application.
  2016. # NJV        4/1/91        Updated Header
  2017. #########################################################################
  2018. task LaunchTwitch(AppName, Folder :="",LaunchApp := 1,SetDir := 1) begin
  2019.     x := typespeed(50);
  2020.     Temp := Global Appverify;
  2021.     Global PrevAppTitle :=  Global AppTitle;
  2022.     Appverify := 0;
  2023.  
  2024.     CurrApp := Match[application];
  2025.     returnVal := 1;
  2026.  
  2027.     if not( CurrApp.t ~= /≈{AppName}≈/) begin
  2028.         if (not Twitcher(Appname)) begin
  2029.             if (Global isSys7) begin
  2030.                 if (match[menuItem t:/≈{AppName}≈/ m:[menu t:""]]) begin
  2031.                     MenuIt :=match[menuItem t:/≈{AppName}≈/ m:[menu t:""]];
  2032.                     MenuItemName :=MenuIt.t;
  2033.                     Selectmenuitem("{MenuItemName}", "");
  2034.                 end;
  2035.                 else if (LaunchApp = 1) begin
  2036.                     if (not match[window o:1 t:/≈{Folder}≈/ k:{ [scrollBar e:true] }]!)
  2037.                         SelectMenuItem("{Folder}", "");
  2038.                     for theTime := 1 to 3 begin
  2039.                         if (match[window o:1 t:/≈{Folder}≈/ k:{ [scrollBar e:true]}]!)
  2040.                             theTime := 4;    # break from loop
  2041.                         else
  2042.                             wait(1);
  2043.                     end;
  2044.                     if not (theTime = 5) begin    # couldn't open folder
  2045.                         LogStr("!@#$% Couldn't open folder titled {Folder} containing requested Alias.");
  2046.                         returnVal := 0;
  2047.                     end;
  2048.                     else begin
  2049.                         typeStr("{AppName}");
  2050.                         SelectMenuItem('Open','File');
  2051.                     end;
  2052.                 end;
  2053.                 else begin
  2054.                     returnVal := 0;
  2055.                 end;
  2056.             end;
  2057.             else Begin    # running under 6.x Operating System
  2058.                 if not( CurrApp.t ~= /≈MiniLauncher≈/) begin
  2059.                     if not (selectMenuItem('MiniLauncher')) begin
  2060.                         LogStr('MiniLauncher could not be found in the Apple Menu - Aborting');
  2061.                         returnVal := 0;
  2062.                     end;
  2063.                     wait(1);
  2064.                 end;
  2065.                 if (returnVal)    # if we found MiniLauncher
  2066.                     MiniLaunch(AppName,LaunchApp,SetDir);
  2067.             end;
  2068.         end;
  2069.     end;
  2070.     if (returnVal) begin    # we're OK so far - keep checking
  2071.         for foo := 1 to 2
  2072.             DialogCheck("memory");
  2073.     end;
  2074.  
  2075.     if (returnVal)
  2076.         matchApp(0);    # To update the Global AppTitle to the new App
  2077.     Appverify :=temp;
  2078.     typespeed(x);
  2079.     return(returnVal);
  2080. end;
  2081.  
  2082.  
  2083. #########################################################################
  2084. #                             IsSubString(str1, str2)
  2085. #=======================================================================
  2086. # Author:              SL
  2087. # Description:        Checks to see if str1 is in str2.
  2088. # Parameters:        str1    :=    Substring to be searched for.
  2089. #                    str2    :=    String.
  2090. # Returns:            false    :=    str1 is not in str2.
  2091. #                    true    :=    str1 is in str2.
  2092. #=======================================================================
  2093. # History:
  2094. #     SL            6/20/90        Created
  2095. #     KTA            9/4/90        Rewrote
  2096. #    NJV            4/1/91        Shortened
  2097. #########################################################################
  2098. task IsSubString(str1, str2) begin
  2099.      return ( str2 ~= /≈"{str1}"≈/);
  2100. end; # isSubString()
  2101.  
  2102. #########################################################################
  2103. #                         FindPos(char, str, startPos)
  2104. #=======================================================================
  2105. # Author:          SL
  2106. # Description:    Finds the first occurence of char in str starting
  2107. #                from startPos.
  2108. # Parameters:    char    :=    A character to be searched for.
  2109. #                str        :=     String.
  2110. #                startPos:=    Starting position to be searched.
  2111. # Returns:        0        :=    Char is not in str starting from
  2112. #                            startPos.
  2113. #                pos        :=     Char position of its first occurence
  2114. #                            starting from startPos.
  2115. #=======================================================================
  2116. # History:
  2117. #    SL        6/20/90            Created
  2118. #########################################################################
  2119. task FindPos(char, str, startPos:= 1)
  2120. begin
  2121.     numStr := card str;
  2122.     
  2123.     # If start position is greater than the string length, return 0 #
  2124.     if (startPos > numStr)
  2125.         return(0);
  2126.     
  2127.     for i:= startPos to numStr do
  2128.         begin
  2129.             if (char = str[i])
  2130.                 return(i);
  2131.         end; # for
  2132.     return(0);
  2133. end; # findPos()
  2134.  
  2135.  
  2136. #########################################################################
  2137. #                         Substring(_String,_StartChar,_NumChar)
  2138. #=======================================================================
  2139. # Author:          PF 
  2140. # Description:    returns the first _NumChar characters of the passed _String
  2141. #                starting at _StartChar.
  2142. # Parameters:    _String - String to use
  2143. #                _StartChar - Character to start making substring from
  2144. #                _NumChar - Integer number of characters to return
  2145. # Returns:        string
  2146. # Assumptions:    none
  2147. #=======================================================================
  2148. # History:
  2149. #    PF        8/23/90        Created
  2150. #    PF        8/27/90        Updated to handle begin anywhere in string
  2151. ##########################################################################
  2152. task Substring(_String,_StartChar,_NumChar) begin
  2153.     # first see if number of characters is greater then length of string
  2154.     # and return the whole end of the string if it is.
  2155.     if (_NumChar > ((card _String ) - _StartChar + 1)) begin
  2156.         return (Substring (_String,_StartChar,((card _String) - _StartChar) +1));
  2157.         
  2158.     end;
  2159.     else begin
  2160.         # create a string of first _NumChar characters and return it.
  2161.         _NewString:="";                            #start with an empty string
  2162.         for _CharCount :=_StartChar to ((_StartChar + _NumChar) - 1)
  2163.             _NewString := _NewString + _String[_CharCount];
  2164.             return (_NewString);
  2165.     end;
  2166. end; #Substring task
  2167.  
  2168. #########################################################################
  2169. #                Scrapbook(requestElement,ccpFlag,pasteFlag)
  2170. #========================================================================
  2171. # Author:        KTA
  2172. # Description:    This routine will select the scrapbook, scroll to the
  2173. #                designated requestElement position, select Cut, Copy, Paste,
  2174. #                or Clear from the Edit menu, close the scrapbook if under System
  2175. #                6.0.x, and then select Paste if the pasteFlag parameter is 1.
  2176. # Parameters:    requestElement - the element in the scrapbook to scroll to
  2177. #                ccpFlag -    1 for copy
  2178. #                            2 for cut
  2179. #                            3 for paste
  2180. #                            4 for clear
  2181. #                pasteFlag - 1 to paste after closing Scrapbook
  2182. #                            0 not to paste after closing Scrapbook
  2183. # Returns:        0 - Couldn't complete operation
  2184. #                element - Scrapbook element that operation took place on
  2185. # Examples:        Scrapbook(2) will scroll the horizontal bar to the
  2186. #                second entry and then copy, close and paste.
  2187. # Assumptions:    That the scrollbars are present. That the string
  2188. #                'Scrapbook' appear somewhere in the name
  2189. #========================================================================
  2190. # History:
  2191. #     KTA        11/28/89    Created
  2192. #    KTA     5/14/90        handles its own scrollbars instead of ScrollWindow() 
  2193. #                        Checks for enabled scrollbars
  2194. #                        MatchApp(0); for App verification
  2195. #    NJV        7/3/90        (x,y) parameters are now just (x)
  2196. #                        added copyFlag - 1 if copy, 0 if cut
  2197. #    NJV        7/5/90        Added pasteFlag - 1 if paste, 0 if don't paste
  2198. #                        Added error checking to assure requested scrapbook
  2199. #                        element exists.
  2200. #                        Added error checking to make sure Cut or Copy menu
  2201. #                        item selection was successful - if not, routine
  2202. #                        closes ScrapBook and aborts (returning 0).
  2203. #    NJV/KTA    7/13/90        took out wait
  2204. #                        added while ! match [window t:'Scrapbook' o:1]!);
  2205. #    NJV/KTA    7/17/90        changed copyFlag to ccpFlag for paste and clear
  2206. #                        bug fix from previous re-work
  2207. #    NJV        10/9/90        If 7.0, calls LaunchTwitch instead of closing Scrapbook
  2208. #    NJV        11/27/90    Updated documentation
  2209. #    KTA        1/9/91        Added scrap := 1 to 4
  2210. #    KTA        1/24/91        Took out a unneeded comment about checking in the Apple Menu
  2211. #    KTA        1/30/91        put in fix for 7.0ß4 where sound button is control [1]
  2212. #    KTA        2/18/91        Took out integration - May put this in the Integrate.lib
  2213. #    KTA        2/25/91        LaunchTwitch PreviousApp if can launch Scrapbook
  2214. #########################################################################
  2215. task Scrapbook(requestElement,ccpFlag := 1,pasteFlag := 1) 
  2216. begin
  2217.     println "==========================================================";
  2218.     LogStr("Performing Scrapbook DA test.");
  2219.  
  2220.     if (requestElement = 3) begin
  2221.         requestElement := 2;
  2222.         logStr("####Patch so we don't try to copy the sound in 7.0ß4");
  2223.     end;
  2224.     if (ccpFlag > 4)
  2225.         ccpFlag := 1;    # old default is copy
  2226.         
  2227.     If(LaunchTwitch('Scrapbook')) begin
  2228.         For Scrap := 1 to 4 begin
  2229.             scBook := match [window t:'Scrapbook' o:1]!;
  2230.             if (scBook)
  2231.                 scrap := 4;
  2232.             else
  2233.                 launchTwitch("Scrapbook");
  2234.         end;
  2235.         LogStr("Opened the Scrapbook");
  2236.         if(scBook.k[1].t = 'Play Sound') #put in fix for 7.0ß4 where sound button is control [1]
  2237.             SkrollBar := scBook.k[2];
  2238.         else
  2239.             SkrollBar := scBook.k[1];
  2240.         status := SkrollBar.s;
  2241.         if (status <> { 0, -1 }) begin                # if scrollbar is enabled...
  2242.             error := 0;                                # no errors yet
  2243.             elementCount := status[2] + 1;            # elementCount = number of scrapbook elements
  2244.             currentElement := status[1] + 1;        # currentElement = current position in Scrapbook
  2245.             newCount := elementCount + 1;
  2246.  
  2247.             if (requestElement>elementCount) begin    # if position is greater than total elements in Scrapbook.. 
  2248.                 if (ccpFlag = 1)
  2249.                     LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Copying entry {currentElement} of {elementCount}");
  2250.                 else if (ccpFlag = 3)
  2251.                     LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Pasting to entry {currentElement} of {newCount}");
  2252.                 else begin
  2253.                     LogStr("!@#$% Can∂'t Cut/Clear - Scrapbook entry {requestElement} does not exist! Closing Scrapbook!");
  2254.                     error := 1;    # don't clear or cut if requested item not there
  2255.                 end;
  2256.             end;
  2257.             else begin# we've got a valid Scrapbook entry
  2258.                 scroll SkrollBar a:{requestElement,elementCount};
  2259.                 match [scrollbar s:?status]!;
  2260.                 currentElement := status[1] + 1;        # currentElement = current position in Scrapbook
  2261.                 LogStr("Scrolled to item {currentElement} of {elementCount} of the ScrapBook");
  2262.                 wait(1);
  2263.             end;
  2264.             
  2265.             if (not error) begin
  2266.                 if (ccpFlag = 1) begin    # Copy Item
  2267.                     if (not SelectMenuItem("Copy", "Edit"))    # error - couldn't copy
  2268.                         error := 1;        # prepare to abort
  2269.                 end;
  2270.                 else if (ccpFlag = 2)  begin
  2271.                     if (not SelectMenuItem("Cut", "Edit"))    # error - couldn't cut    
  2272.                         error := 1;        # prepare to abort
  2273.                 end;
  2274.                 else if (ccpFlag = 3)  begin
  2275.                     if (not SelectMenuItem("Paste", "Edit"))    # error - couldn't cut    
  2276.                         error := 1;        # prepare to abort
  2277.                     else
  2278.                         LogStr("Pasted to entry {currentElement} of {newCount}");                        
  2279.                 end;
  2280.                 else if (ccpFlag = 4)  begin
  2281.                     if (not SelectMenuItem("Clear", "Edit"))    # error - couldn't clear    
  2282.                         error := 1;        # prepare to abort
  2283.                 end;
  2284.             end;
  2285.             wait(2);
  2286.             if (Global isSys7)
  2287.                 LaunchTwitch(Global PrevAppTitle);
  2288.             else
  2289.                 CloseWindow();    # close ScrapBook
  2290.             if (error)
  2291.                 return(0);
  2292.             if (pasteFlag)    begin    # if we're supposed to paste back into document, do it
  2293.                 wait(3);
  2294.                 if (SelectMenuItem("Paste", "Edit")) begin
  2295.                     println "==========================================================";
  2296.                     return(1);
  2297.                 end;
  2298.             end;
  2299.             return(currentElement);    # everything went OK
  2300.         end;
  2301.         else begin
  2302.             LogStr('!@#$% The horizontal scroll bar was not enabled to scroll');
  2303.             closeWindow();
  2304.             return(0);
  2305.         end;
  2306.     end;
  2307.     else begin
  2308.         if (Global isSys7)
  2309.             LaunchTwitch(Global PrevAppTitle);
  2310.         return(0);
  2311.     end;
  2312. end; # Scrapbook()
  2313.  
  2314. ########################################################################
  2315. #                        PageSetup()
  2316. #=======================================================================
  2317. # Author:             KTA
  2318. # Description:        For PageSetup routines
  2319. # Parameters:        Nada
  2320. # Returns:            None
  2321. #=======================================================================
  2322. # History:
  2323. # KTA 2/25/91 Created
  2324. ########################################################################
  2325. task PageSetup() begin
  2326.     SelectMenuItem("Page Setup", "File");    #To select Page SetUp…
  2327.     wait(1);
  2328.     SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  2329.     wait(1);
  2330. end;
  2331.  
  2332.  
  2333.  
  2334. ########################################################################
  2335. #                        GetXYRandom(inset, specifier)
  2336. #=======================================================================
  2337. # Author:             SL
  2338. # Description:        Returns a random X and Y coordinate in the specified
  2339. #                    screen or window.
  2340. # Parameters:        inset - ltrb inset from scrn or window
  2341. #                    specifier > 0 ordinality of window to find coords in
  2342. #                              = O coords in window with s:doc g:true and c:true
  2343. #                              < 0 coords in specified screen.  Screen numbe
  2344. #                                is negative of specifier.
  2345. # Returns:            xyRandom - List of random X and Y.  eg. { x, y }
  2346. #=======================================================================
  2347. # History:
  2348. #    SL        4/5/90        Created
  2349. #    NJV        5/13/90        Added scrn parameter
  2350. #    DM        9/23/90        Added option to get random points in front window
  2351. #    DM        9/23/90        Changed so the default is random coords in windows
  2352. #                        rather than screen coords.  
  2353. ########################################################################
  2354. task GetXYRandom(inset := {30,30,30,30}, specifier := 0) begin        
  2355.     (*
  2356.     if (not (IsNumber(specifier)))
  2357.         match [window t:specifier r:?rect]!;
  2358.     else if(specifier > 0)
  2359.         match[window o:specifier r:?rect]!;
  2360.     else if(specifier = 0)
  2361.         match[window s:document r:?rect c:true g:true]!;
  2362.     
  2363.     if (specifier < 0) begin
  2364.         scrList := collect[screen r:?rect]!;
  2365.         ScreenCount := 1;
  2366.         for each theScreen in scrList begin
  2367.             if ScreenCount = -specifier
  2368.                 scr := theScreen;
  2369.             ScreenCount := ScreenCount + 1;
  2370.         end;
  2371.     end;
  2372.     *)
  2373.     theDesc := FindWindow(specifier);
  2374.      
  2375.     if(theDesc) begin
  2376.         rect := theDesc.r;
  2377.         maxX := rect[3] - rect[1] - inset[3];
  2378.         maxY := rect[4] - rect[2] - inset[4];
  2379.         #minX := inset[1];
  2380.         #minY := inset[2];
  2381.         xRandom := random(inset[1], maxX);
  2382.         yRandom := random(inset[2], maxY);
  2383.         xyRandom := { xRandom, yRandom };
  2384.         
  2385.         return(xyRandom);
  2386.     end;
  2387.     else begin
  2388.         LogStr("Couldn't match a window of specifier {specifier} in GetXYRandom");
  2389.         return 0;
  2390.     end;
  2391. end; # getXYRandom()
  2392.  
  2393.  
  2394. #########################################################################
  2395. #                            IsNumber(whatAmI)
  2396. #========================================================================
  2397. # Author:            NJV
  2398. # Description:        This routine determine whether the input parameter is
  2399. #                    a number or not.  This could be done directly in-line,
  2400. #                    but to avoid Developer's having to modify their code,
  2401. #                    I updated this routine so that scripts will still work
  2402. #                    properly unmodified.
  2403. # Parameters:        whatAmI - item to check
  2404. # Returns:            true - the parameter is a number
  2405. #                    false - the parameter is not a number
  2406. # Examples:            IsNumber("Hello");
  2407. # Assumptions:        None
  2408. #========================================================================
  2409. # History:
  2410. #    NJV        5/22/90        Created
  2411. #    NJV        6/25/91        Now uses TypeOf() VU function
  2412. #########################################################################
  2413. task IsNumber(whatAmI) begin
  2414.     return((TypeOf(whatAmI) = 'integer'));
  2415. end; # IsNumber()
  2416.  
  2417. #########################################################################
  2418. #                        PtInRect(thePoint,theRect)
  2419. #========================================================================
  2420. # Author:            NJV
  2421. # Description:        This routine determines whether or not thePoint 
  2422. #                    is contained within theRect (including borders). 
  2423. # Parameters:        thePoint - a list of two integers
  2424. #                    theRect - holds the coordinates of the rectangle.
  2425. # Returns:            true - point lies in the rectangle.
  2426. #                    false - point does NOT lie in the rectangle.
  2427. # Examples:            isIt := PtInRect(thePoint,theRect).
  2428. # Assumptions:        None
  2429. #========================================================================
  2430. # History:
  2431. #    NJV        9/18/90        Created
  2432. #########################################################################
  2433. task PtInRect(thePoint,theRect) begin
  2434.     return( ((thePoint[1] >= theRect[1]) and (thePoint[1] <= theRect[3]))
  2435.             and ((thePoint[2] >= theRect[2]) and (thePoint[2] <= theRect[4])) );
  2436. end;
  2437.  
  2438.  
  2439.  
  2440. #########################################################################
  2441. #                         CenterofScreenClick()
  2442. #=======================================================================
  2443. # Author:          KTA
  2444. # Description:    Clicks in the center of main screen
  2445. # Parameters:    none
  2446. # Returns:        Nada
  2447. #=======================================================================
  2448. # History:
  2449. #    KTA        12/05/90    Added [m:True] to make sure the right screen
  2450. #########################################################################
  2451. task CenterofScreenClick() begin
  2452.     Match[screen r:?x m:true];
  2453.     w := ((x[3]-x[1])/2);
  2454.     h := ((x[4] - x[2])/2);
  2455.     move a:{w,h};
  2456.     click;
  2457.     LogStr('Moved to the center of the screen and clicked');
  2458. end;
  2459.  
  2460. #########################################################################
  2461. #                         Quit(OverWrite, DocName)
  2462. #=======================================================================
  2463. # Author:          KTA
  2464. # Description:    Will turn off the Application Verification scheme, Select
  2465. #                the Quit menu item, check whether or not to save changes,
  2466. #                then reset the App verification scheme to its previous state.
  2467. # Parameters:    OverWrite    1    - Save changes.
  2468. #                            0    - Don't save changes.
  2469. #                DocName        -    The string that will be used to save the document
  2470. #                HowQuit        1    - Select "Quit" from File Menu
  2471. #                            2    - Type Cmd-Q to quit
  2472. # Returns:        Nada
  2473. #=======================================================================
  2474. # History:
  2475. #    KA        8/23/90        Created
  2476. #    NJV        11/25/90    Added KeepScrapOpen parameter to bypass KAs assumption
  2477. #                        that ScrapBook is open (fix in scrapbook for 6.0 world).
  2478. #    KTA        12/18/90    Took out KeepScrapOpen parameter-auto close Scrap
  2479. #    KTA        1/8/91        Moved endTime
  2480. #    KTA        1/9/91        Added HowQuit
  2481. #    KTA        2/18/91        Added While(CheckYesNo)
  2482. #    NJV        4/1/91        Took out Timer
  2483. #########################################################################
  2484. task Quit(OverWrite :=1,DocName:="",HowQuit :=1) begin
  2485.     temp := global Appverify;
  2486.     AppVerify := 0;
  2487.     global startTime;
  2488.     if (HowQuit = 1)
  2489.         SelectMenuItem('Quit','File');     #Quit MenuItem
  2490.     else if (HowQuit = 2)
  2491.         keyEq('q');                        #Key Equiv 'q'
  2492.     while(checkYesNo(overwrite,DocName))
  2493.         wait(3);
  2494.  
  2495.     if match[window o:1 t:"Scrapbook"]!
  2496.         closeWindow(,,'Scrapbook');
  2497.     wait(2);
  2498.     AppVerify := temp;
  2499.     MatchApp();
  2500.     println;
  2501.     println;
  2502. end;
  2503.